Global.asax捕获处理系统异常,插入日志表

来源:互联网 发布:json转字符串 java 编辑:程序博客网 时间:2024/05/21 10:13
Global.asax捕获处理系统异常,插入日志表
 protected void Application_Error(object sender, EventArgs e)        {            # region 系统异常处理            Exception ex = Server.GetLastError();//捕获应用程序的异常            while (ex.InnerException != null)            {                ex = ex.InnerException;            }            string strMessage = ex.Message;            string strStackTrace = ex.StackTrace;            string strUrl = Request.Url.ToString();            bool needExLog = bool.Parse(ConfigurationSettings.AppSettings["NeedExLog"]);            if (needExLog)            {                # region 记录异常日志                BMS_MMS.Model.Log_Exception model = new BMS_MMS.Model.Log_Exception();                model.PageUrl = strUrl;                model.Message = strMessage;                model.StackTrace = strStackTrace;                model.UserID = BMS_MMS.BLL.Sys_User.GetCurUser().ID.ToString();                model.LogDate = System.DateTime.Now;                BMS_MMS.BLL.Log_Exception bll = new BMS_MMS.BLL.Log_Exception();                bll.Insert(model);                # endregion                Response.Redirect("~/Error.aspx?ID=" + model.ID);            }            else            {                strMessage = Server.UrlEncode(strMessage);                Response.Redirect("~/Error.aspx?MSG=" + strMessage);            }            # endregion        }

0 0
原创粉丝点击