• c# .net 我的Application_Error 全局异常抓取处理


      protected void Application_Error(object sender, EventArgs e)
            {
                //在出现未处理的错误时运行的代码         
                Exception objError = Server.GetLastError().GetBaseException();
                string errortime = string.Empty;
                string erroraddr = string.Empty;
                string errorinfo = string.Empty;
                string errorsource = string.Empty;
                string errortrace = string.Empty;
                string errormethodname = string.Empty;
                string errorclassname = string.Empty;

                errortime = "发生时间:" + System.DateTime.Now.ToString();
                erroraddr = "发生异常页: " + System.Web.HttpContext.Current.Request.Url.ToString();
                errorinfo = "异常信息: " + objError.Message;
                errorsource = "错误源:" + objError.Source;
                errortrace = "堆栈信息:" + objError.StackTrace;
                errorclassname = "发生错误的类名" + objError.TargetSite.DeclaringType.FullName;
                errormethodname = "发生错误的方法名:" + objError.TargetSite.Name;
                //清除当前异常 使之不返回到请求页面
                Server.ClearError();
                lock (this)
                {
                    //文件不存在就创建,true表示追加
                    // writer = new System.IO.StreamWriter(file.FullName, true);
                    #endregion
                    string ip = "用户IP:" + Request.UserHostAddress;
                    string log = errortime + "##" + erroraddr + "##" + ip + "##" + errorclassname + "##" + errormethodname + "##" + errorinfo + "##" + errorsource + "##" + errortrace.Replace(" ", "<br>");
                   
                    LogHelper.Error(new Exception(log), this.GetType().Name, "Global");
                }
                Response.Write("程序出现异常状态,请联系管理员");
            }

  • 相关阅读:
    python内置的魔术命令(builtin magic commands)
    绘制ROC曲线
    python with语句中的变量有作用域吗?
    Visual Studio上编译ncnn
    loss函数学习笔记
    Install zeal on ubuntu16.04
    cmake方式使用vlfeat
    整理读研期间用过、改进过、写过的代码
    ubuntu下使用matplotlib绘图无法显示中文label
    error: each element of 'ext_modules' option must be an Extension instance or 2-tuple
  • 原文地址:https://www.cnblogs.com/jicheng/p/6398034.html
Copyright © 2020-2023  润新知