Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Source property was not set before writing to the event log.

Status
Not open for further replies.

Skittle

ISP
Sep 10, 2002
1,528
US
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:-
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'.
 
Resolved it.

It was a bit oblique.
I was coding the project on a remote drive and for some reason when I copied it to my C drive and recompiled it works fine. I think somewhere along the line I was simply installing the wrong version.



Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top