public void errorLog()
{
try
{
}
catch (Exception ex)
{
var strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now + "\r\n";
var str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n",
ex.GetType().Name, "ProcDataThread:" + ex.Message, ex.StackTrace);
WriteLog(str);
MessageBox.Show("发生错误,请查看程序日志!", "系统错误", MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
public static void WriteLog(string str)
{
if (!Directory.Exists("ErrLog"))
{
Directory.CreateDirectory("ErrLog");
}
using (var sw = new StreamWriter(@"ErrLog\ErrLog.txt", true))
{
sw.WriteLine(str);
sw.WriteLine("---------------------------------------------------------");
sw.Close();
}
}
捕捉异常记录错误日志
最新推荐文章于 2021-01-30 18:19:21 发布