问题
I have a custom C# Windows Service.
It has detailed logging set up and graceful shutdown processes, which include logging out when shutting down.
Specifically, the program is an .exe
, which calls
ServiceBase.Run(container.Resolve<MyWindowsService>());
in its Program.Main()
method.
I have (NLog) logging in the (overridden) MyWindowsService.OnStop()
method, and in a finally
block of the Program.Main()
method.
The service is installed and configured for Automatic
start in Windows Services
When running, or stopping "normally" all that logging works just fine. If I manually stop the service it's all good, and I get my logging.
But when I log out, the service never logs that it shut-down, and sometimes isn't running again when I log back in.
I think that I've observed all 3 of: * Log back in, and it's still running, with no "I just started" logs. * Log back in, and it's still running, but the logs say that it restarted. * Log back in, and it's not running.
The 3rd option seems to correlate with Event Logs saying
Event 7034 Source - service control manager.
MyWindowsService
terminated unexpectedly. It has done this X time(s).
But telling me nothing else.
How can I further debug this issue? I want to understand what exactly is happening to me service and why it sometimes crashes.
Separate question asked, for "How do I ensure it always starts up?". This question is about actually fixing the logging, though.
来源:https://stackoverflow.com/questions/60302978/log-to-debug-windows-service-dying-on-sign-out