• 使用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();
            }
  • 相关阅读:
    Vivian's Problem UVA
    Prime k-tuple UVA
    M
    Make a Crystal UVA
    Cryptography Reloaded UVALive
    Gauss Prime UVA
    Discrete Square Roots UVALive
    The Bells are Ringing UVALive
    Huge Mods UVA
    指数循环节
  • 原文地址:https://www.cnblogs.com/dashi/p/4034630.html
Copyright © 2020-2023  润新知