How to record logs to TXT files in ASP. NET

Source: Internet
Author: User


Methods for recording logs to TXT files in ASP. NET:

Public   Static   Void Addlogerr ( String Spname, String Errdescribe)
String Tracingfile =   " C:/inetpub/wwwroot/log/ " ;// Server. mappath ("/log /")
If ( ! System. Io. Directory. exists (tracingfile ))
System. Io. Directory. createdirectory (tracingfile );
String Filename = Datetime. Now. tostring ( " Yyyymmdd " ) +   " . Txt " ;
Tracingfile + = Filename;
If (Tracingfile ! = String. Empty)
System. Io. fileinfo File =   New System. Io. fileinfo (tracingfile );
System. Io. streamwriter debugwriter =   New System. Io. streamwriter (file. Open (system. Io. filemode. append, system. Io. fileaccess. Write, system. Io. fileshare. readwrite ));
Debugwriter. writeline (spname +   " ( "   + System. datetime. Now. tostring () +   " ) "   +   " : " );
Debugwriter. writeline (errdescribe );
Debugwriter. writeline ();
Debugwriter. Flush ();
Debugwriter. Close ();


Call method:

Addlogerr ("Applyform","Originalreason:"+Originalreason );

Log example:


code highlighting produced by actipro codehighlighter (freeware)

--> applyform (20:13:48):
originalreason: 5lia5zob6bur5p2/logs + 45lia5zob6bur5p2/5pyj6zm

Related Article

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: 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.