简体   繁体   English

Windows服务未记录到事件日志

[英]Windows Services Not Logging To Event Log

I have a windows service that fails to start under some circumstances. 我的Windows服务在某些情况下无法启动。 When it fails to start the sequence of events suggest that my .NET code in the service has probably run, but no event log messages appear. 当它无法启动时,事件序列提示该服务中的.NET代码可能已运行,但没有事件日志消息出现。

Event log messages show up when the service starts properly. 服务正常启动时,将显示事件日志消息。

How does the event log work? 事件日志如何工作? And how does the windows service manager work? Windows服务管理器如何工作?

If a service times out (which is what happens) is it possible that the event log messages associated with that service would be trashed? 如果服务超时(发生了什么情况),与该服务关联的事件日志消息是否有可能被废弃?

If a service times out does that mean it has called my .NET code at all? 如果服务超时,是否就意味着它已经调用了我的.NET代码? My startup method calls a background thread so I don't understand why the service would time out. 我的启动方法调用了后台线程,所以我不明白为什么服务会超时。

Doesn't really add up. 并不是真的加起来。

The event log requires explicit logging actions. 事件日志需要显式的日志记录操作。 The ones you see from start and shutdown are created by the service control manager of the operating system. 您从启动和关闭中看到的内容是由操作系统的服务控制管理器创建的。 To get any logging beyond that, you need to use the System.Diagnostics.EventLog class explicitly. 为了获得更多的日志记录,您需要显式使用System.Diagnostics.EventLog类。

Edit : If you do that, and still don't see the messages, it either means that the log operating was not executed, or it failed, perhaps with a Win32Exception. 编辑 :如果您这样做,但仍然看不到消息,则说明未执行日志操作,或者它失败了,可能是Win32Exception。

It really depends on what your code is doing. 这实际上取决于您的代码在做什么。 Why not debug it using Debugger.Launch() or wrap the starting code in a try ... catch to capture the error message. 为什么不使用Debugger.Launch()对其进行Debugger.Launch()或者将起始代码包装在try ... catch以捕获错误消息。 It's unlikely the service will log much to the event log... that's the developers job :) 该服务不太可能将大量日志记录到事件日志中……这是开发人员的工作:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM