Exception Error log
生活随笔
收集整理的這篇文章主要介紹了
Exception Error log
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
public class ExceptionsHandler{/// <summary>/// 寫錯誤日志/// </summary>/// <param name="e">Exception</param>public static void WriteError(Exception e){try{//每天創建一個錯誤日志,到服務器虛擬目錄下string path = "~/Error/" + DateTime.Today.ToString("yyyy-MM-dd") + ".log";if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath(path))){///如果文件不存在,則創建Log
File.Create(System.Web.HttpContext.Current.Server.MapPath(path)).Close();}//寫日志文件using (StreamWriter w = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(path))){//寫詳細錯誤信息w.WriteLine("Error Recode:");w.WriteLine("\tError Time:{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));w.WriteLine("\tError Address:" + System.Web.HttpContext.Current.Request.Url.ToString());w.WriteLine("\tTarget Site:" + e.TargetSite);w.WriteLine("\tError Message:" + e.Message);w.WriteLine("\tError InnerMessage:" + e.InnerException.Message);w.WriteLine("\tError HelpLink:" + e.HelpLink);w.WriteLine("\tError StackTrace:" + e.StackTrace);w.WriteLine("************************************************************************************");w.WriteLine("\r\n");w.Flush();w.Close();}}//不需要拋出異常catch (Exception){//throw new Exception("寫日志出錯!" + ex.Message);
}}}
?
轉載于:https://www.cnblogs.com/Areas/archive/2013/01/07/2848666.html
總結
以上是生活随笔為你收集整理的Exception Error log的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python-21-socket编程
- 下一篇: 从最大似然估计到最小二乘法