G
Guest
I hope this is just something stupid I'm missing and someone can easily point
out my error. I'm trying to do a few turorials on windows services, and the
couple I found so far just create an event log and write an entry on start
and stop. I build the projects and install them fine, but when I run the
service it starts and stops instantly. The service is not creating the
custom event log I wanted it to but instead adds an error message in the
Application event log saying that the source I declared for my eventlog was
not registered to the eventlog I declaired. I'm not sure I understand
because I found several articles on line saying if you included a custom
source and log for an EventLog component, if they were not present they were
automatically created. Here is the code I use to intialize the event log:
Public Sub New()
MyBase.New()
' This call is required by the Component Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call
' Test if the event log exists; if not, create it
If (Not System.Diagnostics.EventLog.SourceExists("ServiceOne")) Then
EventLog.CreateEventSource("ServiceOne", "ServiceOneLog")
End If
' Set the source and log properties for the event log
EventLog1.Source = "ServiceOne"
EventLog1.Log = "ServiceOneLog"
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
EventLog1.WriteEntry("ServiceOne is starting.")
End Sub
I'm not sure why this is failing. All the examples I find say this should
work. Do I need to set something up to be allowed to create an event log?
I've tried setting up the service as both a local service and as a service
under an admin user with now luck? Can anyone give me any advice on what I'm
missing?
Chris
out my error. I'm trying to do a few turorials on windows services, and the
couple I found so far just create an event log and write an entry on start
and stop. I build the projects and install them fine, but when I run the
service it starts and stops instantly. The service is not creating the
custom event log I wanted it to but instead adds an error message in the
Application event log saying that the source I declared for my eventlog was
not registered to the eventlog I declaired. I'm not sure I understand
because I found several articles on line saying if you included a custom
source and log for an EventLog component, if they were not present they were
automatically created. Here is the code I use to intialize the event log:
Public Sub New()
MyBase.New()
' This call is required by the Component Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call
' Test if the event log exists; if not, create it
If (Not System.Diagnostics.EventLog.SourceExists("ServiceOne")) Then
EventLog.CreateEventSource("ServiceOne", "ServiceOneLog")
End If
' Set the source and log properties for the event log
EventLog1.Source = "ServiceOne"
EventLog1.Log = "ServiceOneLog"
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
EventLog1.WriteEntry("ServiceOne is starting.")
End Sub
I'm not sure why this is failing. All the examples I find say this should
work. Do I need to set something up to be allowed to create an event log?
I've tried setting up the service as both a local service and as a service
under an admin user with now luck? Can anyone give me any advice on what I'm
missing?
Chris