aarontham
asked on
vb.net 2008 error log file
how can i create and write error log file in vb.net 2008?
Pls provide some code
Pls provide some code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here's how you can do it:
Public Sub WriteError(ByVal e As Exception)
'Set this to the name of your application
Dim AppName As String = "My application"
'Set this to the name of the Log (like "Application" log)
Dim LogName As String = "MyLog"
Dim log As New EventLog()
If Not EventLog.SourceExists(AppN ame) Then _
EventLog.CreateEventSource (AppName, LogName)
log.Source = AppName
Dim msg As String = "The following unhandled exception has occurred in the " & _
AppName & " application:" & vbCrLf & vbCrLf & _
e.Message
'Write the error to the EventLog
log.WriteEntry(msg, System.Diagnostics.EventLo gEntryType .Error)
End Sub
Write an error like this:
Dim errMessage As String = "write this error"
WriteError(New Exception(errMessage))
MsgBox("done")
You can view the entry in your log:
Open Windows Administrative Tools | Event Viewer
Public Sub WriteError(ByVal e As Exception)
'Set this to the name of your application
Dim AppName As String = "My application"
'Set this to the name of the Log (like "Application" log)
Dim LogName As String = "MyLog"
Dim log As New EventLog()
If Not EventLog.SourceExists(AppN
EventLog.CreateEventSource
log.Source = AppName
Dim msg As String = "The following unhandled exception has occurred in the " & _
AppName & " application:" & vbCrLf & vbCrLf & _
e.Message
'Write the error to the EventLog
log.WriteEntry(msg, System.Diagnostics.EventLo
End Sub
Write an error like this:
Dim errMessage As String = "write this error"
WriteError(New Exception(errMessage))
MsgBox("done")
You can view the entry in your log:
Open Windows Administrative Tools | Event Viewer
http://www.codeguru.com/columns/vb/article.php/c6561
http://www.codeproject.com/KB/vb/ErrorsAndEventsExample.aspx