469,097 Members | 1,240 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,097 developers. It's quick & easy.

Question about EventLog

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,

--

Dennis
Jun 27 '08 #1
2 1045
On May 20, 9:54 am, Dennis <nob...@nowhere.comwrote:
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,

--

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.

Chris

Jun 27 '08 #2
On Tue, 20 May 2008 11:16:57 -0700 (PDT), Chris Dunaway
<du******@gmail.comwrote:
>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...

--

Dennis
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Steven | last post: by
1 post views Thread by martin | last post: by
3 posts views Thread by Ben | last post: by
2 posts views Thread by =?Utf-8?B?Sm9l?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.