Windows 服务和事件日志的设置项目
我有一个安装 Windows 服务的安装项目。
我们正在自定义日志中注册一个事件日志源,该事件日志源应该由 winservice 项目使用(如何以及为什么并不重要)。
我的问题是安装项目尝试默认创建事件日志源。通过这样做,它会收到一条错误消息(“错误 1001”源 XXX 已存在于本地计算机上
)并回滚。
我到处都找过了,但找不到在哪里完成注册或如何将其关闭。
如何强制 Windows 服务或安装项目不创建事件日志源?
I got a setup project that installs a windows service.
We are registering a event log source in a custom log which should be used by the winservice project (how and why is not important).
My problem is that the setup project tries to create an event log source per default. By doing so it get's an error message ("Error 1001" source XXX already exists on local computer
) and rolls back.
I have looked everywhere and I cannot find where the registration is done or how I can turn it off.
How can I force the windows service or setup project to NOT create an event log source?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以删除默认的
EventLogInstaller
:或者,您可以修改
Log
属性:现在事件将成功记录到MyLog,并且服务启动/停止事件仍将记录到应用程序日志中。
(来源:serviceInstaller 组件及其默认的 EventLogInstaller)
You can remove the default
EventLogInstaller
:Alternatively, you can modify the
Log
property:Now events will be successfully logged to MyLog, and service start/stop events will still be logged to the Application log.
(source: serviceInstaller component and its default EventLogInstaller)
我猜想当您卸载该服务时,某些内容未正确卸载,特别是在事件日志中。
要恢复重新安装服务的能力,我发现(感谢本文)您需要在注册表 (regedit.exe) 中删除此键:
I guess that when you uninstall the service, something is not correctly uninstalled, expecially in the event log.
To restore the ability to reinstall the service again, I discovered (thanks to this article) you need to remove this key in the registry (regedit.exe):
这只是根据我的测试的猜测。
安装程序项目(或 WindowService 类)自动创建一个与
myService.ServiceName
同名的事件源。这很可能是因为每次启动/停止服务时都会将启动/停止消息写入日志。这些消息需要一个来源。换句话说:您不需要创建与 ServiceName 同名的源,因为它已经为您完成了。
This is only a guess based on my tests.
The installer project (or the WindowService class) creates an event source automatically with the same name as
myService.ServiceName
. This is most likely because Start/Stop messages are written to the log each time a service is started / stopped. And those messages need a source.In other words: You do not need to create a source with the same name as the ServiceName as it is done for you.