Reputation: 3047
I have a multithreaded windows service that will unpredictably stop running once every 24 hours or so. I am writing to the event log and that's going through just fine, but whenever the service crashes there are no messages in the event log (even that the service stopped, despite having AutoLog=true). Is there a way to have uncaught exceptions written straight to the log, even if they aren't in the original thread?
Upvotes: 0
Views: 533
Reputation: 185693
First of all, threads that you spawn should have a top level try { } ... catch { }
block that catches (and, if appropriate, either swallows or rethrows) exceptions thrown on them. Apart from that, you can use the AppDomain.UnhandledException
event to catch any unhandled exceptions and log them out.
Upvotes: 1