Home All Groups Group Topic Archive Search About

Creating a custom log

Author
15 Apr 2005 5:36 PM
UJ
I am trying to have a service write out to a custom log in the event log.
I'm using the following code:


Dim lsEventSource As String = "test1234"
Dim lsEventLog As String = "CustomLog"

If (Not EventLog.SourceExists(lsEventSource)) Then
EventLog.DeleteEventSource(lsEventSource)
EventLog.CreateEventSource(lsEventSource, lsEventLog)
End If

Dim llogEventLog As EventLog
llogEventLog = New EventLog
llogEventLog.Source = lsEventSource

llogEventLog.WriteEntry("This is a test spot for the event log.")


Can anybody tell me what's wrong with the code? No matter what I put for the
lsEventLog name, it always is being written to the Application log. I've
also tried changing the name of the EventSource to something else just to
see what happens then.....

Author
15 Apr 2005 6:12 PM
Joseph Bittman MCAD
April 15, 2005

   The problem is when you create the new event log llogeventlog, you are
not specifying the name of the log...


Dim lsEventSource As String = "test1234"
Dim lsEventLog As String = "CustomLog"

If (Not EventLog.SourceExists(lsEventSource)) Then
EventLog.DeleteEventSource(lsEventSource)
EventLog.CreateEventSource(lsEventSource, lsEventLog)
End If

Dim llogEventLog As EventLog
llogEventLog = New EventLog
llogEventLog.Source = lsEventSource
llogEventLog.Log = lsEventLog  ' Add custom log name
llogEventLog.WriteEntry("This is a test spot for the event log.")

This will specify the custom log as the one to write to. Have a great day!

                                              Joseph Bittman MCAD
                                  Microsoft Certified Application Developer


Show quoteHide quote
"UJ" <U*@nowhere.com> wrote in message
news:eAYTrGeQFHA.3868@TK2MSFTNGP10.phx.gbl...
>I am trying to have a service write out to a custom log in the event log.
>I'm using the following code:
>
>
> Dim lsEventSource As String = "test1234"
> Dim lsEventLog As String = "CustomLog"
>
> If (Not EventLog.SourceExists(lsEventSource)) Then
> EventLog.DeleteEventSource(lsEventSource)
> EventLog.CreateEventSource(lsEventSource, lsEventLog)
> End If
>
> Dim llogEventLog As EventLog
> llogEventLog = New EventLog
> llogEventLog.Source = lsEventSource
>
> llogEventLog.WriteEntry("This is a test spot for the event log.")
>
>
> Can anybody tell me what's wrong with the code? No matter what I put for
> the lsEventLog name, it always is being written to the Application log.
> I've also tried changing the name of the EventSource to something else
> just to see what happens then.....
>
>
>