问题
I have a windows service which fails in Init() method and throws some exception , so only way for me to check what the error is by looking at the event log. I want to debug the windows service, but the problem is that i can attach debugger only when service is rnning, in my case it fails in Init() method only. Any idea ?
回答1:
you can programatically attach the debugger as the first line in the function:
Debugger.Launch ();
after adding the using statement:
using System.Diagnostics;
回答2:
What I usually do is to have a class with a static void Main()
entry point, which I can then temporarily assign in the project properties. From there, I call the same startup functions that are called when the app is run as a service.
回答3:
probably you can get the dumps of the crash using DebugDiag or windbg.
is your service C++ or C#.
Also maybe it is just a first chance exception and not really a crash. Can you provide more info on the failure.
来源:https://stackoverflow.com/questions/1914296/how-to-debug-windows-service-which-fails-in-init-method