【Vegas原创】Err Log的写法

2年前 (2022) 程序员胖胖胖虎阿
243 0 0

 

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() ;
            }
        }

 

版权声明:程序员胖胖胖虎阿 发表于 2022年11月1日 下午12:32。
转载请注明:【Vegas原创】Err Log的写法 | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...