5

我在 Windows 服务中使用 Microsoft 日志解析器。该程序在常规网页中运行,但是当我将代码放入 Windows 服务时,它不起作用。我将 Breakponts 放在 Windows 服务中,但是当我运行代码时,程序不会在断点处停止。因此,通过我的故障排除,我将问题缩小到 Log Parser 软件和 Linq。所以无论是 Linq 还是日志解析器软件都在制造问题。你们有什么想法吗?

4

4 回答 4

5

您需要将调试器直接附加到 Windows 服务。这可能会对您有所帮助:http: //msdn.microsoft.com/en-us/library/7a50syb3%28VS.80%29.aspx

于 2009-10-13T21:53:48.163 回答
2

I have done this many ways in the past depending on how the program runs. I think the easiest way is done with a if #DEBUG preprocessor directive around the Debugger.Launch() that way when you've built the project optimized the Debugger.Launch() call won't be compiled into the assembly.

One way we have also done done this task is with System.Windows.Forms.MessageBox.Show("attach") which allowed us to manually attach to the debugger whenever the "attach" dialog was displayed.

The last way which I do not prefer is to change the behavior of your service based on commandline params passed in. Basically opting NOT to start the services using ServiceBase.Run whenever a particular param was fired off, but calling a class that encapsulates the behavior/main function of the service.

于 2009-10-14T01:23:51.667 回答
2

是否要调试 OnStart 方法?如果是这样,您可以使用System.Diagnostics.Debugger.Launch() orSystem.Diagnostics.Debugger.Break()方法在 on start 方法运行时有机会附加调试器,否则附加调试器总是迟到。

于 2009-10-13T22:03:00.037 回答
2

我认为胖猫关于将调试器附加到服务进程的建议听起来是对的。如果这仍然不起作用,请尝试使用Debug.WriteLineDebugView

于 2009-10-13T22:06:12.487 回答