Link to home
Start Free TrialLog in
Avatar of aarontham
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
Avatar of nmarun
nmarun
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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(AppName) 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.EventLogEntryType.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