views:

302

answers:

2

Hi All,

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.

+2  A: 

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

David Kiff
Thanks, but I am referring to our code that is writing to the event log. If our code runs it will write to the event log and that is what I am looking for. I guess I am asking is if the event log doesn't have messages in it does that definately mean it is not getting to our code?
peter
I have suspicians you see that our code is being run because of the reason the service fails. A security error is being logged saying the windows firewall can't ask the user about our app. Our app is exposing WCF, so that would suggest our code is being run.
peter
No, it might mean the writing to the event log is throwing the exception! Yeah from what your saying, it does sound like its hitting your code.. more debugging/investigation probably required though to be sure..
David Kiff
+2  A: 

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.

Martin v. Löwis
Yeah, and that is what I am doing / looking out for. See the comment above.
peter
@peter: ah, ok. See my edit.
Martin v. Löwis
Right. Good point. An exception could have happened, but that is always hard when an exception happens in logging code, you can't exactly log it!
peter
The other tricky thing overall is that I cannot replicate this issue on my machine and it is intermittent anyway so I can not just debug it
peter