Methods for recording logs to TXT files in ASP. NET:
Code
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:
Code
Addlogerr ("Applyform","Originalreason:"+Originalreason );
Log example:
Code
code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/
--> applyform (20:13:48):
originalreason: 5lia5zob6bur5p2/logs + 45lia5zob6bur5p2/5pyj6zm