zoukankan      html  css  js  c++  java
  • 使用Application_Error捕获站点错误并写日志

    Global.ascx页面使用以下方法即可捕获应用层没有try cath的错误     

       protected void Application_Error(Object sender, EventArgs e)

            {

                //在出现未处理的错误时运行的代码
                Exception ex = Server.GetLastError();

                Exception exp = ex.GetBaseException();
                if (exp.GetType().Name.Equals("HttpException"))
                {//排除404页面
                    if (404 == ((HttpException)exp).GetHttpCode()) { return; }
                }
                StringBuilder sbReqParams = new StringBuilder();
                sbReqParams.Append(" User-Agent:" + HttpUtility.UrlDecode(this.Request.UserAgent));
                sbReqParams.Append(" Form:"+ HttpUtility.UrlDecode(this.Request.Form.ToString()));
                sbReqParams.Append(" Cookies:"+ HttpUtility.UrlDecode(this.Request.Form.ToString()));
                LogHelper.WriteLog(string.Format("应用程序出错: 错误页面:{0} 请求参数:{1} ", this.Request.Url, sbReqParams.ToString()), ex);


                Server.ClearError();
            }
  • 相关阅读:
    【Scrum】2.18
    【scrum】2.22
    绿色软件 Vs 安装软件
    【Scrum】2.21
    【scrum】2.15
    读《design pattern》有感
    让广告再播一会儿~
    Qt::日志处理
    终于在博客园开通了
    惹毛程序员的十件事
  • 原文地址:https://www.cnblogs.com/dashi/p/4034630.html
Copyright © 2011-2022 走看看