zoukankan      html  css  js  c++  java
  • .net中的Global的错误日志

    void Application_Error(object sender, EventArgs e) 

    // 在出现未处理的错误时运行的代码 
    Exception ex = Server.GetLastError().GetBaseException(); 
    StringBuilder str = new StringBuilder(); 
    str.Append(" " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss")); 
    str.Append(" .客户信息:"); 


    string ip = ""; 
    if (Request.ServerVariables.Get("HTTP_X_FORWARDED_FOR") != null) 

    ip = Request.ServerVariables.Get("HTTP_X_FORWARDED_FOR").ToString().Trim(); 

    else 

    ip = Request.ServerVariables.Get("Remote_Addr").ToString().Trim(); 

    str.Append(" Ip:" + ip); 
    str.Append(" 浏览器:" + Request.Browser.Browser.ToString()); 
    str.Append(" 浏览器版本:" + Request.Browser.MajorVersion.ToString()); 
    str.Append(" 操作系统:" + Request.Browser.Platform.ToString()); 
    str.Append(" .错误信息:"); 
    str.Append(" 页面:" + Request.Url.ToString()); 
    str.Append(" 错误信息:" + ex.Message); 
    str.Append(" 错误源:" + ex.Source); 
    str.Append(" 异常方法:" + ex.TargetSite); 
    str.Append(" 堆栈信息:" + ex.StackTrace); 
    str.Append(" --------------------------------------------------------------------------------------------------"); 
    //创建路径 
    string upLoadPath = Server.MapPath("~/log/"); 
    if (!System.IO.Directory.Exists(upLoadPath)) 

    System.IO.Directory.CreateDirectory(upLoadPath); 

    //创建文件 写入错误 
    System.IO.File.AppendAllText(upLoadPath + DateTime.Now.ToString("yyyy.MM.dd") + ".log", str.ToString(), System.Text.Encoding.UTF8); 
    //处理完及时清理异常 
    Server.ClearError(); 
    //跳转至出错页面 
    Response.Redirect("~/error.html"); 

  • 相关阅读:
    K近邻 Python实现 机器学习实战(Machine Learning in Action)
    sklearn-SVC实现与类参数
    从核函数到SVM原理--sklearn-SVM实现
    基于scikit-learn包实现机器学习之KNN(K近邻)-完整示例
    java集合框架
    面向对象第一周心得体会
    java面试总结
    Aaa
    测试
    在Java中执行Tomcat中startup.bat
  • 原文地址:https://www.cnblogs.com/jerry123/p/7762980.html
Copyright © 2011-2022 走看看