VB.Net - EventLog

Windows comes with a built in Event Viewer. You can post information to the Event Viewer as an alternative to posting to logs. here are my notes

Event Viewer

Windows comes with a built in Event Viewer. You can post information to the Event Viewer as an alternative to posting to logs. (For me I used it as a debugging tool for new installations)

Here’s a sample of it’s usage

Public Shared Sub Main()
    Dim sSource As String = "SasdDirWatchSrv" ' hmm having spaces in here triggered errors

    If Not EventLog.SourceExists(sSource) Then
        ' Create the source, if it does not already exist.
        ' An event log source should not be created and immediately used.
        ' There is a latency time to enable the source, it should be created
        ' prior to executing the application that uses the source.
        ' Execute this sample a second time to use the new source.
        EventLog.CreateEventSource(sSource, sSource)
        Console.WriteLine("CreatingEventSource")
        'The source is created.  Exit the application to allow it to be registered.
        Return
    End If

    ' Create an EventLog instance and assign its source.
    Dim myLog As New EventLog()
    myLog.Source = sSource
    myLog.Log = sSource

    ' Write an informational entry to the event log.    
    myLog.WriteEntry("Test")

End Sub

Experiences

I think you cannot have a space in the .Log command.

THe first time I ran this program I had a problem. The second time I ran it it worked. Apparently creating an event source takes awhile.