How to write entry in log file in case of exception generation
Following code is used to create the log file and writing exception in that
Step 1:- create one module named ultra module and write the procedure named CreateFile in that
Public Sub CreateFile(ByVal strPath As String, ByVal error As String)
Dim wfile As StreamWriter
Try
wfile = New StreamWriter(strPath, True)
wfile.WriteLine(Engid & " : " & strline.Trim & " : " & Now())
wfile.Close()
Catch ex As Exception
Finally
wfile = Nothing
End Try
End Sub
Step2:- Use the try catch block and call the function from catch block to write entry from that
Try
Catch ex As Exception
UltraModule.CreateFile(Me.Logfile, "Error in Uploading Files" & ex.Message)
End Try
Special Note :- This code inserts all the exception occures in that file. ITs very usefule when large amount of code is been executed .