I have put together a simple service program.
It has a file watcher to recognise when files are moved into a folder and it will move them somewhere else.
I have included event log write events so I can log what it does.
I write an eventlog event within the 'On Start' event on the service but the program seems to fail on it. When I start the service program it crashes and puts the following error to the event log:-
I have set the properties of the 'Source' for my log both within the properties window of visual studio and hard coded in the On Start event yet still I get this error. As far as I can see I have coded the log exactly the same as on a windows form program that works fine. Can anybody advise me where I am going wrong?
Dazed and confused.
Remember.. 'Depression is just anger without enthusiasum'.
It has a file watcher to recognise when files are moved into a folder and it will move them somewhere else.
I have included event log write events so I can log what it does.
I write an eventlog event within the 'On Start' event on the service but the program seems to fail on it. When I start the service program it crashes and puts the following error to the event log:-
Code:
Service cannot be started. System.ArgumentException: Source property was not set before writing to the event log.
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type)
at ServiceFileMonitor.ServiceFileMonitor.OnStart(String[] args)
I have set the properties of the 'Source' for my log both within the properties window of visual studio and hard coded in the On Start event yet still I get this error. As far as I can see I have coded the log exactly the same as on a windows form program that works fine. Can anybody advise me where I am going wrong?
Code:
Protected Overrides Sub OnStart(ByVal args() As String)
' -------------
' START SERVICE
' -------------
Try
ReadParameters()
FileSystemWatcher1.Path = strDeliveryFolder
FileSystemWatcher1.EnableRaisingEvents = True
strMessage = "ServiceFileMonitor Started."
EventLog1.Source = "ServiceFileMonitor"
EventLog1.WriteEntry(strMessage, System.Diagnostics.EventLogEntryType.Information)
Catch ex As Exception
strMessage = "Error. " + ex.Message
EventLog1.WriteEntry(strMessage, System.Diagnostics.EventLogEntryType.Error)
SendErrorEmail(strMessage)
End Try
Dazed and confused.
Remember.. 'Depression is just anger without enthusiasum'.