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();
            }
  • 相关阅读:
    NSIS打包electron程序为exe安装包
    3、electron打包生成exe文件
    7、Shiro加密和加盐
    6、Shiro之自定义realm
    5、Shiro之jdbcRealm认证授权
    Jmeter-提取Json数据进行关联
    CentOS7 adb
    centos 7 安装pip和pip3
    最新Centos7安装python3并与python2共存
    centos7安装chrome浏览器
  • 原文地址:https://www.cnblogs.com/dashi/p/4034630.html
Copyright © 2011-2022 走看看