Windows服务中的自定义事件日志记录 [英] Custom Event Logging in a Windows Service
问题描述
在项目安装程序中,我正在创建自定义事件日志.但是,当我的服务启动时,我的所有日志都将转到应用程序",而不是常规的日志.以下是我添加到安装程序中的代码.
In the project installer i am creating a custom event log. But when my service starts my all logs are going to the "Application" instead of my cuustom log. Below is the code which i have added to installer.
// Create Event Source and Event Log
EventLogInstaller logInstaller = new EventLogInstaller();
logInstaller.Source = "MyServices";
logInstaller.Log = "MyService Events";
Installers.Add(logInstaller);
另外,服务的名称是MyService.exe.
Furthurmore the name of service is MyService.exe.
当我卸载并重新安装该服务时,安装失败并显示以下安装日志;
When I uninstall and re-install the service, i installation fail with the following install log;
运行事务处理的安装.
Running a transacted installation.
开始安装的安装阶段.见内容D:\ MyService \ MyService \ bin \ Release \ MyService.exe的日志文件大会的进度.该文件位于D:\ MyService \ MyService \ bin \ Release \ MyService.InstallLog.
Beginning the Install phase of the installation. See the contents of the log file for the D:\MyService\MyService\bin\Release\MyService.exe assembly's progress. The file is located at D:\MyService\MyService\bin\Release\MyService.InstallLog.
在安装阶段发生异常.System.ArgumentException:源MyServices已存在本地计算机.
An exception occurred during the Install phase. System.ArgumentException: Source MyServices already exists on the local computer.
安装的回滚阶段已开始.见内容的日志文件D:\ MyService \ MyService \ bin \ Release \ MyService.exe程序集的进度.该文件位于D:\ MyService \ MyService \ bin \ Release \ MyService.InstallLog.
The Rollback phase of the installation is beginning. See the contents of the log file for the D:\MyService\MyService\bin\Release\MyService.exe assembly's progress. The file is located at D:\MyService\MyService\bin\Release\MyService.InstallLog.
回滚阶段成功完成.
交易安装已完成.
这就是我写日志条目的方式;
And this is how i write log entry;
EventLog.WriteEntry("MyServices",logMessage,logType);
EventLog.WriteEntry("MyServices", logMessage, logType);
有人可以帮助我我在做什么错.
Can someone please help me what wrong i am doing.
推荐答案
我遇到了类似的问题,并通过以下方式解决了该问题:
I had a similar problem and solved it by:
- 停止当前服务.
- 关闭任务管理器,服务管理工具和Windows事件查看器.
- 使用intallutil.exe/u卸载当前服务.
- 删除当前服务的事件日志注册表项.(这很重要!)(\ HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ EventLog \ yourCurrentLogName)您可以找到当前日志,并可以在Windows事件查看器下确认删除.
- 使用installutil.exe重新安装服务.
- 重新启动Windows.(这也很重要!)我不确定是否有必要.但是,即使我注销了,我仍然遇到错误.自从我重新启动Windows以来一切都很好.(也许AWS缓存了什么?)
这篇关于Windows服务中的自定义事件日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!