1 public static void SaveExceptionLog(Exception ex, string methodName) 2 { 3 using (TextWriter tw = new StreamWriter(new System.Web.UI.Page().Server.MapPath("~/App_Data/LogErrorWXHandler_" + DateTime.Now.Ticks + ".txt"))) 4 { 5 //StackTrace stackTrace = new StackTrace(true);//也可以使用这种方式 6 //string methodName = stackTrace.GetFrame(1).GetMethod().Name.ToString(); 7 tw.WriteLine(methodName); 8 tw.WriteLine(ex.Message); 9 tw.WriteLine(ex.Source + ":" + ex.GetType() + "," + ex.StackTrace); 10 tw.WriteLine(ex.InnerException.Message); 11 tw.Flush(); 12 tw.Close(); 13 } 14 }
本文介绍了一种在.NET环境中记录异常日志的方法,通过创建一个静态方法SaveExceptionLog来保存异常信息到文件中,包括方法名、异常消息、源、类型、堆栈跟踪及内部异常消息。
798

被折叠的 条评论
为什么被折叠?



