保存異常日誌記錄

/*****************global.asax************************/
void Application_Error(object sender, EventArgs e)
    {
        // 在出現未處理的錯誤時運行的代碼
        Exception error = GetExp(Server.GetLastError());
        HttpContext context = HttpContext.Current;
        System.Text.StringBuilder sb = new StringBuilder();
        sb.Append(error.Message);
        sb.Append(error.Source);
        sb.Append(error.StackTrace);
        SiteLog.Add(sb.ToString());//自己定義的日誌記錄方法


    }

    Exception GetExp(Exception ex)
    {
        return ex.InnerException == null ? ex : ex.InnerException;
    } 

/*****************************************/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章