Using System. IO; Using System. diagnostics; Namespace Webapplication1 { Public Class Filetext { Public Static String Fileaddress = " C: \ error.txt " ; /// <Summary> /// Record the wrong class name and method name and error message /// </Summary> /// <Param name = "classname"> Error Class Name </Param> /// <Param name = "ex"> Error instance </Param> Public Static Void Record (exception ex ){ Try {Filestream FS = Null ; If (! File. exists (fileaddress) {FS = New Filestream (fileaddress, filemode. Create );} Else {FS =New Filestream (fileaddress, filemode. append);} stacktrace St = New Stacktrace ( True ); String Transfermethod = ST. getframe ( 1 ). Getmethod (). Name. tostring (); streamwriter SW = New Streamwriter (FS); Sw. writeline ( " ------------------------------ " ); Sw. writeline ( " Date: " + Datetime. Now. tostring ( " G " ); Sw. writeline ( " Method for calling error records: " + Transfermethod); Sw. writeline ( " Method for triggering the error: " + Ex. targetsite. tostring (); Sw. writeline ( " Error message: " + Ex. Message. tostring (); Sw. writeline ( " ------------------------------ " ); Sw. Close ();} Catch (Ioexception IOE ){}} Public Static Void Writestring ( String Str) {filestream FS = Null ; If (! File. exists (fileaddress) {FS = New Filestream (fileaddress, filemode. Create );} Else {FS = New Filestream (fileaddress, filemode. append);} stacktrace St = New Stacktrace ( True ); String Transfermethod = ST. getframe ( 1 ). Getmethod (). Name. tostring (); streamwriter SW = New Streamwriter (FS); Sw. writeline ( " ------------------------------ " ); Sw. writeline ( " Date: " + Datetime. Now. tostring ( " G " ); Sw. writeline ( " Error message: " + Str); Sw. writeline ( " ------------------------------ " ); Sw. Close ();}}}