Windows services are not logged in the event log

I have a Windows service that won't start under some circumstances. When it fails to start the sequence of events, suppose my .NET code in the service is probably running, but no event log messages are displayed.

Event log messages are displayed when the service starts correctly.

How does the event log work? And how does the Windows Service Manager work?

If the service times out (what happens), is it possible that the event log messages associated with that service get erased?

Should the service timeout mean it called my .NET code at all? My startup method calls a background thread, so I don't understand why the service would be shut down.

Doesn't really add up.

+2


source to share


2 answers


The event log requires explicit registration actions. The ones you see from startup and shutdown are created by the operating system's service control manager. To get any entries, you must explicitly use the System.Diagnostics.EventLog class .



Edit . If you do this and still do not see the message, it either means that the work in the log was not done, or it failed, possibly with a Win32Exception.

+3


source


It really depends on what your code is doing. Why not debug it with Debugger.Launch()

or wrap the source in try

... catch

to capture the error message. It's unlikely that the service will write much to the event log ... that the developers are working :)



+2


source







All Articles