zoukankan      html  css  js  c++  java
  • 【Vegas原创】Err Log的写法

    try
    {
    //try的内容。 一般为page_load所有内容
    }    

    catch(Exception ex)
                {
                
                    SaveError(ex,
    this.Context,this.Request) ;
                }


    err程序:

            public static void SaveError(Exception ex,HttpContext hc,HttpRequest hr)
            {
                
    string temp ;
                StreamWriter sw ;
     
                
    //如果存在文件
                if(File.Exists(hr.PhysicalApplicationPath+@"\Error.txt"))
                {
                    sw 
    = File.AppendText(hr.PhysicalApplicationPath+@"\Log\SummaryError.txt") ;
                    temp 
    = DateTime.Now.ToString()+ "---------------------By Vegas----------------------------\r\n";
                    temp 
    += "错误消息:" + ex.Message +"\r\n";
                    temp 
    += "导致错误的应用程序或对象的名称:" + ex.Source +"\r\n";
                    temp 
    += "堆栈内容:" + ex.StackTrace +"\r\n";
                    temp 
    += "引发异常的方法:" + ex.TargetSite +"\r\n";
                    temp 
    += "引发异常的方法:" + ex.TargetSite +"\r\n";
                    temp 
    += "错误页面" +hr.RawUrl + "\r\n\r\n";
                    sw.WriteLine(temp) ;
                    sw.Close() ;
                }
                
    else 
                {
                    sw 
    = File.CreateText(hr.PhysicalApplicationPath+@"\Log\SummaryError.txt") ;
                    temp 
    = DateTime.Now.ToString()+ "----------------------By Vegas------------------------------\r\n";
                    temp 
    += "错误消息:" + ex.Message +"\r\n";
                    temp 
    += "导致错误的应用程序或对象的名称:" + ex.Source +"\r\n";
                    temp 
    += "堆栈内容:" + ex.StackTrace +"\r\n";
                    temp 
    += "引发异常的方法:" + ex.TargetSite +"\r\n";
                    temp 
    += "引发异常的方法:" + ex.TargetSite +"\r\n";
                    temp 
    += "错误页面" +hr.RawUrl + "\r\n\r\n";
                    sw.WriteLine(temp) ;
                    sw.Close() ;
                }
            }
    喜欢请赞赏一下啦^_^
  • 相关阅读:
    在Java中如何优雅地判空
    软件可以流氓到什么程度?从卸载步骤就可以看出来!
    面试中常问的List去重问题,你都答对了吗?
    为什么程序员都不喜欢使用switch而使用if来做条件跳转
    那些年,我们一起卸载过的软件…
    趣图:当我捕获Bug的时候
    9个成功的微服务设计的基础知识
    5.1 包装类
    4.9 初始化块
    4.8 继承与组合
  • 原文地址:https://www.cnblogs.com/amadeuslee/p/3744676.html
Copyright © 2011-2022 走看看