.net中错误日志的写入
来源:互联网 发布:耳麦测试软件 编辑:程序博客网 时间:2024/05/16 12:20
1 在.cs中执行存储过程
2
3 try
4
5 {}
6
7 catch(Exception ex)
8 {
9 cm.Connection.Close() ;
10 qiao.Value ="fail";
11 PublicUnit.SaveError(ex,this.Context,this.Request) ;
12 }
13
14
15
16 写日志的编写
17
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 }
38
2
3 try
4
5 {}
6
7 catch(Exception ex)
8 {
9 cm.Connection.Close() ;
10 qiao.Value ="fail";
11 PublicUnit.SaveError(ex,this.Context,this.Request) ;
12 }
13
14
15
16 写日志的编写
17
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 }
38
- .net中错误日志的写入
- .net中错误日志的写入
- .net中错误日志的写入
- asp.net错误日志写入
- asp.net错误日志写入
- asp.net错误日志写入
- asp.net错误日志写入
- ASP.NET Application_Error错误日志写入
- ASP.NET Application_Error错误日志写入
- ASP.NET Application_Error错误日志写入
- .net C# web程序运行中错误日志写入文本文件中
- asp.net中如何把应用程序错误写入事件日志(注册事件源)
- .NET中日志信息写入Windows日志中解决方案
- asp.net中当服务器出错时显示指定的错误页面,同时把错误信息写入系统日志文件的探讨
- Asp.net 自定义错误处理并写入系统日志
- 错误写入日志
- 写入错误日志
- 如何用在asp.net中写入事件日志
- 半导体基础(三)
- 最近很累
- 实现验证码
- 英语考试过后
- 利用XML实现通用WEB报表输入和输出
- .net中错误日志的写入
- 另类搞笑MV—齐天大圣孙悟空
- YUV主要的采样格式
- Shawn the Rock.
- 火狐浏览器
- 常用的JavaScript脚本集合
- 超强开始菜单
- 火狐浏览器(firefox)简体中文最新版下载:
- 防止ACCESS数据库被下载的9种方法