Writing of error logs in. Net

Source: Internet
Author: User
Error

1 executing stored procedures in. CS
 2
 3 try
 4
 5 {}
 6
 7 catch (Exception ex)
& nbsp;8    {
 9     cm. Connection.close ();
10     Qiao. Value = "Fail";
11     publicunit.saveerror (ex,this. Context,this. Request);
12   }

14 

16 Write log writing
-
-public static void Saveerror (Exception ex,httpcontext hc,httpreques T hr)
19   {
20    string temp;
21    StreamWriter SW;

23   //If there is a file
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 = "error message:" + ex. Message + "\ n";
29     temp = "The name of the application or object that caused the error:" + ex. Source + "\ n";
30     temp = "Stack contents:" + ex. StackTrace + "\ n";
31     Temp + = "method that throws an exception:" + ex. TargetSite + "\ n";
32     temp = "error page" +hr. Rawurl + "\ n";
a
34     SW. WriteLine (temp);
35     SW. Close ();
36   }
37  }







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.