peter
peter

Reputation: 13501

Windows Services Not Logging To Event Log

I have a windows service that fails to start under some circumstances. When it fails to start the sequence of events suggest that my .NET code in the service has probably run, but no event log messages appear.

Event log messages show up when the service starts properly.

How does the event log work? And how does the windows service manager work?

If a service times out (which is what happens) is it possible that the event log messages associated with that service would be trashed?

If a service times out does that mean it has called my .NET code at all? My startup method calls a background thread so I don't understand why the service would time out.

Doesn't really add up.

Upvotes: 2

Views: 5153

Answers (2)

David Kiff
David Kiff

Reputation: 1210

It really depends on what your code is doing. Why not debug it using Debugger.Launch() or wrap the starting code in a try...catch to capture the error message. It's unlikely the service will log much to the event log... that's the developers job :)

Upvotes: 2

Martin v. Löwis
Martin v. Löwis

Reputation: 127537

The event log requires explicit logging actions. The ones you see from start and shutdown are created by the service control manager of the operating system. To get any logging beyond that, you need to use the System.Diagnostics.EventLog class explicitly.

Edit: If you do that, and still don't see the messages, it either means that the log operating was not executed, or it failed, perhaps with a Win32Exception.

Upvotes: 3

Related Questions