分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

.net中错误日志的写入

发布时间:2023-09-06 01:13责任编辑:蔡小小关键词:错误日志

18 public static void SaveError(Exception ex,HttpContext hc,HttpRequest hr)
19   {
20    string temp ;
21    StreamWriter sw ;
22
23    //如果存在文件
24    if(File.Exists(hr.PhysicalApplicationPath+@"\Error.txt"))
25    {
26     sw = File.AppendText(hr.PhysicalApplicationPath+@"\Error.txt") ;
27     temp = DateTime.Now.ToString() + "------------------------------------------------------------------------------------\n";
28     temp += "错误消息:" + ex.Message +"\n";
29     temp += "导致错误的应用程序或对象的名称:" + ex.Source +"\n";
30     temp += "堆栈内容:" + ex.StackTrace +"\n";
31     temp += "引发异常的方法:" + ex.TargetSite +"\n";
32     temp += "错误页面" +hr.RawUrl + "\n\n";
33
34     sw.WriteLine(temp) ;
35     sw.Close() ;
36    }
37   }

.net中错误日志的写入

原文地址:http://www.cnblogs.com/fengyingwang/p/7591153.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved