Link to home
Start Free TrialLog in
Avatar of jmsjms
jmsjmsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Writing to the Event Log vb net

Hi,  I'm trying to write to the event log in a Windows Service Application I'm developing.

The Service builds OK. But the service just stops as soon as it starts without any logging.


Any idea?

    If Not System.Diagnostics.EventLog.SourceExists("MyService") Then
      System.Diagnostics.EventLog.CreateEventSource("NyService", "MyService Log")
    End If

    _eventLog = New EventLog()
    _eventLog.Source = "MyService"
    _eventLog.WriteEntry(" Service started.", EventLogEntryType.Information)
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

is this code inside OnStart() function in your window service class?
do u have exception handling on your code to detect errors?
you can also use Debugger.Break() inside the class in order to debug the code when the service starts.
SOLUTION
Avatar of jmsjms
jmsjms
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jmsjms

ASKER

Sounds good!  Can this be done with the LE version of install shield?
Not sure. You can create another exe which you can ask user to launch as admin when you find out, in your main program, that event source does not exist.
Avatar of jmsjms

ASKER

But you cant have any user-interaction with a service so how could you do this?
There are work arounds but i think first thing to do is to determine if installshield LE can help you.
Avatar of jmsjms

ASKER

I've run out of time to devote to this, so cant confirm whether installsheild LE can help here of not.

I'll mark this as an answer so people can see what I found out and one possible way forward.
Avatar of jmsjms

ASKER

My comment indicates that just getting a service to create the event log source will not work (despite some examples on the web) UNLESS the service has admin rights.

Codecruisers suggestion that it's done as part of the installation is a good idea but I can't confirm this works yet.