zoukankan      html  css  js  c++  java
  • 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按行读取并替换
    python 爬取网页内容
    file.write(str),file.writelines(sequence)
    04Spring_bean 后处理器(后处理Bean),BeanPostProcessor ,bean创建时序,动态代理
    03Spring_bean的创建和作用域以及生命周期
    02Spring_Ioc和DI介绍
    01Spring_基本jia包的导入andSpring的整体架构and怎么加入日志功能
    错题724-java
    05传智_jbpm与OA项目_部门模块中增加部门的jsp页面增加一个在线编辑器功能
    04传智_jbpm与OA项目_部门模块改进_直接在BaseAction中实现ModelDriven<T>
  • 原文地址:https://www.cnblogs.com/jicheng/p/6398034.html
Copyright © 2011-2022 走看看