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 .


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: