Question about EventLog

D

Dennis

I have a service with the following startup code...
Protected Overrides Sub OnStart(ByVal args() As String)
If Not Diagnostics.EventLog.SourceExists("MyService") Then
Diagnostics.EventLog.CreateEventSource("MyService", "MyServiceLog")
End If

Dim _eventLog As New Diagnostics.EventLog
_eventLog.Source = "MyService"
_eventLog.WriteEntry(CStr(TimeOfDay) + " started", EventLogEntryType.Information)

AddHandler m_listTimer.Elapsed, AddressOf myTimerElapsed
m_listTimer.Enabled = True
End Sub

When I start the service I see a new entry under...

Computer Management(local)
System Tools
Event Viewer
Application
MyServiceLog <--- new entry

But the actual event I write gets logged with the Application events.

My question is, can I get the events that I write to go under
MyServiceLog? What am I doing wrong?

TIA,
 
C

Chris Dunaway

I have a service with the following startup code...




When I start the service I see a new entry under...

Computer Management(local)
System Tools
Event Viewer
Application
MyServiceLog <--- new entry

But the actual event I write gets logged with the Application events.

My question is, can I get the events that I write to go under
MyServiceLog? What am I doing wrong?

TIA,

You're calling a Shared method from an instance variable, expecting it
to use your new event source. C# disallows this, but VB allows it.
There are overloads of the WriteEntry method that are not Shared, but
I think those only write to the default event log.

You need to call it like this:

Diagnostics.EventLog.WriteEntry("MyServiceLog", CStr(TimeOfDay) + "
started", EventLogEntryType.Information)

I hope this helps.

Chris
 
D

Dennis

You're calling a Shared method from an instance variable, expecting it
to use your new event source. C# disallows this, but VB allows it.
There are overloads of the WriteEntry method that are not Shared, but
I think those only write to the default event log.

You need to call it like this:

Diagnostics.EventLog.WriteEntry("MyServiceLog", CStr(TimeOfDay) + "
started", EventLogEntryType.Information)

I hope this helps.

Thanks. All is now well...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top