Menulis kesalahan log di .net
Penulis:Eve Cole
Waktu Pembaruan:2009-06-30 16:12:20
1 在.cs中执行存储过程
2
3 mencoba
4
5 {}
6
7 tangkapan (Pengecualian ex)
8 {
9 cm.Koneksi.Tutup() ;
10 qiao.Nilai = "gagal";
11 PublicUnit.SaveError(misal,ini.Konteks,ini.Permintaan) ;
12 }
13
14
15
16 tahun
17
18 public static void SaveError(Pengecualian ex,HttpContext hc,HttpRequest jam)
19 {
suhu 20 senar;
21 Penulis Aliran sw ;
22
23 //如果存在文件
24 if(File.Exists( hr.PhysicalApplicationPath+@"Error.txt "))
25 {
26 sw = File.AppendText( hr.PhysicalApplicationPath+@"Error.txt ") ;
27 suhu = DateTime.Now.ToString() + "-------------------------------------- ----------------------------------------------N";
28 temp += "错误消息:" + ex.Pesan +"n";
29 temp += "导致错误的应用程序或对象的名称:" + ex.Sumber +"n";
30 suhu += "堆栈内容:" + ex.StackTrace +"n";
31 temp += "引发异常的方法:" + ex.TargetSite +"n";
32 suhu += "错误页面" +jam.RawUrl + "nn";
33
34 sw.WriteLine(temp) ;
35 sw.Tutup() ;
36 }
37 }
38