dotnet-win32-service icon indicating copy to clipboard operation
dotnet-win32-service copied to clipboard

Unhandled exception – provide the application access to the exception details.

Open DaveSenn opened this issue 6 years ago • 2 comments

Hi Martin

If I understood the code correctly, the library is catching unhandled exceptions and then calls Win32ServiceHost.ReportServiceStatus without throwing the exception?

Is there a way to notify the application about such an exception? …So that the application for example can write a last “emergency” log statement bevor it exits. Maybe an event similar to AppDomain.CurrentDomain.UnhandledException?

Btw. Really cool library, thanks for sharing it.

DaveSenn avatar Mar 12 '18 13:03 DaveSenn

I've already heard feedback about not really being able to debug exceptions. The problem with throwing is that it breaks the connection to windows' service management system.

I'm open to suggestions for how to handle this best.

The netfx ServiceBase reports to the event log, which also isn't available in .net core yet, it will be part of the windows compatibility pack in the .net core 2.1 timeframe. This also contains ServiceBase for .net core which kind of obsoletes part of this library (except for service creation/update/delete).

Two options:

  • Wait until .NET Core 2.1 release and write to the event log on windows (the compatibility pack should be available for netstandard2.0 but released alongside .NET Core 2.1). I don't want to create another PInvoke wrapper over the event log APIs, esp. since there is one coming in the compatibility pack.
  • Provide a hook on the service host like events, IExceptionReporter or similar.

dasMulli avatar Mar 12 '18 14:03 dasMulli

Having an entry in the event log (with .Net Core 2.1) would work for me.

DaveSenn avatar Mar 12 '18 15:03 DaveSenn