如何将程序中出现的异常生成log文件并保存

来源:百度知道 编辑:UC知道 时间:2024/06/18 00:38:26
如何在C#中将异常包存成日志文件(log)·····

try
{
...
}
catch(Exception ex)
{
File.AppendAllText(Server.MapPath("路径"), ex.ToString(), Encoding.BigEndianUnicode);
}

File.AppendAllText("YourLogName.log", Exception.Message);

捕获到一场进行操作

捕获异常,然后在异常代码块中,找出异常类型,储存到数据库!