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 }