Browse Source

LOG日志修改

master
sc 2 years ago
committed by 忱 沈
parent
commit
dd6bb40912
  1. 41
      App.xaml.cs
  2. 9
      EX/Exchange.xaml
  3. 23
      EX/Exchange.xaml.cs

41
App.xaml.cs

@ -54,39 +54,44 @@ namespace formula_manage
e.Handled = true;
if (e.Exception.InnerException == null)
{
MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!" + Environment.NewLine
// + "(2)错误源:" + e.Exception.Source + Environment.NewLine
+ "详细信息:" + e.Exception.Message + Environment.NewLine
// + "(4)报错区域:" + e.Exception.StackTrace
MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!"
+ "(1)错误" + Environment.NewLine
+ "(2)错误源:" + e.Exception.Source + Environment.NewLine
// + (3)详细信息:" + e.Exception.Message + Environment.NewLine
// + "(4)报错区域:" + e.Exception.StackTrace
);
}
else
{
MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!" + Environment.NewLine
// + "(2)错误源:" + e.Exception.InnerException.Source + Environment.NewLine
+ "错误信息:" + e.Exception.Message + Environment.NewLine
// + "(4)详细信息:" + e.Exception.InnerException.Message + Environment.NewLine
// + "(5)报错区域:" + e.Exception.InnerException.StackTrace
MessageBox.Show("发生了一个无法处理的错误!请联系SUNLIGHT处理!"
+ "(1)错误" + Environment.NewLine
// + "(2)错误源:" + e.Exception.InnerException.Source + Environment.NewLine
+ "(3)错误信息:" + e.Exception.Message + Environment.NewLine
// + "(4)详细信息:" + e.Exception.InnerException.Message + Environment.NewLine
// + "(5)报错区域:" + e.Exception.InnerException.StackTrace
);
}
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
if (!File.Exists(logpath + Log_time + "Log.txt"))//检查日志文件并写入启动日志
string log_path = logpath +"\\ERR" +Log_time + ".txt";
if (!File.Exists(log_path))//检查日志文件并写入启动日志
{
FileStream fs = new FileStream(logpath + Log_time + "Log.txt", FileMode.CreateNew, FileAccess.Write);//创建写入文件
FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建写入文件
StreamWriter wr = new StreamWriter(fs);//创建文件
wr.WriteLine("||["+ Log_time + "];[Error source] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("||[" + Log_time + "];[Details] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("||[" + Log_time + "];[Error area] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("[" + Log_time + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString());
wr.WriteLine("[" + Log_time + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
wr.WriteLine("[" + Log_time + "];[Detailed] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
wr.WriteLine("[" + Log_time + "];[Error area] ||" + e.Exception.StackTrace.ToString());
wr.Close();
}
else
{
FileStream fs = new FileStream(logpath + Log_time + "Log.txt", FileMode.CreateNew, FileAccess.Write);//创建写入文件
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
StreamWriter wr = new StreamWriter(fs);//创建文件
wr.WriteLine("||[" + Log_time + "];[Error source] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("||[" + Log_time + "];[Details] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("||[" + Log_time + "];[Error area] ||" + e.Exception.Source + Environment.NewLine);
wr.WriteLine("[" + Log_time + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString());
wr.WriteLine("[" + Log_time + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
wr.WriteLine("[" + Log_time + "];[Detailed] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
wr.WriteLine("[" + Log_time + "];[Error area] ||" + e.Exception.StackTrace.ToString());
wr.Close();
}
}

9
EX/Exchange.xaml

@ -7,16 +7,17 @@
mc:Ignorable="d"
Title="Exchange" Height="720" Width="1280" MinHeight="720" MinWidth="1280" Background="#FFE0E0E0">
<Grid>
<DataGrid x:Name="gridLog" Margin="5,5,0,5" HorizontalAlignment="Left" Width="250">
<DataGrid x:Name="gridLog" Margin="5,5,0,5" HorizontalAlignment="Left" Width="250" HeadersVisibility ="Column" Background="White" BorderBrush="White"
CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
CanUserResizeColumns="False" CanUserSortColumns="False" >
<DataGrid.Columns>
<!--列信息绑定-->
<DataGridTextColumn Binding="{Binding Name}" Header="文件" Width="200" MaxWidth="200" MinWidth="100"/>
<DataGridTextColumn Binding="{Binding Name}" Header="容量" Width="50" MaxWidth="50" MinWidth="50"/>
<DataGridTextColumn Binding="{Binding Length}" Header="容量" Width="50" MaxWidth="50" MinWidth="50"/>
</DataGrid.Columns>
</DataGrid>
<RichTextBox x:Name="Log" Margin="255,5,5,5" IsReadOnly="True" VerticalScrollBarVisibility="Visible" Background="White">
<RichTextBox x:Name="Log" Margin="255,5,5,5" IsReadOnly="True" VerticalScrollBarVisibility="Visible" Background="White" SelectionBrush="White">
<FlowDocument>
<Paragraph>
<Run Text="LOG"/>

23
EX/Exchange.xaml.cs

@ -29,17 +29,32 @@ namespace formula_manage.EX
InitializeComponent();
logdataTable.Columns.Add("Name", typeof(string));
logdataTable.Columns.Add("length", typeof(int));
logdataTable.Columns.Add("Length", typeof(int));
LOG_file();
}
private void LOG_file()//建立列表
{
DirectoryInfo loginfo = new DirectoryInfo(System.Environment.CurrentDirectory + "\\Exchange"); //new文件夹
FileInfo[] logFile = loginfo.GetFiles("*.log");//生成文件夹中的文件名合集
// logdataTable.ItemsSource = logFile;//加载合集
DataRow FileRow = logdataTable.NewRow();
foreach (var item in loginfo.GetFiles())
{
// DataRow FileRow = logdataTable.NewRow();
FileRow["Name"] = item.Name;
FileRow["Length"] = item.Length/1024;
logdataTable.Rows.Add(FileRow);
}
gridLog.ItemsSource = logdataTable.DefaultView;
// FileInfo[] logFile = loginfo.GetFiles("*.log");//生成文件夹中的文件名合集
//gridLog.ItemsSource = logFile;//加载合集
// DataRow row = logdataTable.NewRow(); //ID列
//logdataTable. =
// logFile.fill()
//gridLog.DisplayMemberPath = "Name"; // 显示文件名
// //gridLog.DataContext = "Name"; // 显示文件名
// gridLog.ItemsSource = logFile;//加载合集
}
}
}

Loading…
Cancel
Save