【发布时间】:2017-01-20 09:58:17
【问题描述】:
我有一个 Windows 服务。我正在努力让 EventLog 正常工作。
在 Windows 服务的构造函数中我这样做:
public MyService()
{
InitializeComponent();
AutoLog = false;
if (!EventLog.SourceExists(ServiceName))
{
EventSourceCreationData creationData = new EventSourceCreationData(ServiceName, ServiceName);
EventLog.CreateEventSource(creationData);
}
}
运行该服务后,我没有收到任何异常,但在 Event Viewer 的 Application and Services Logs 下看不到任何内容! (即使在计算机重置后)。
我检查了我的注册表,我的服务出现在
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MyService
不在这里:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\MyService
我通过以管理员身份打开的 Visual Studio 的 VS2015 开发人员命令提示符安装 Windows 服务。
为什么在那儿?为什么不在事件日志中?为什么我在事件查看器中看不到它?
谢谢!
【问题讨论】:
-
ServiceName变量的值是多少? -
@Vijai "MyService" 重要吗?
标签: c# .net logging windows-services event-viewer