【发布时间】:2020-06-11 04:25:44
【问题描述】:
我正在开发一个新的 Windows 服务,并按照instruction 中提供的步骤进行操作。
在服务类中,我做的和文章差不多
static EventLog _eventLog;
public CMSMetadata()
{
InitializeComponent();
_eventLog = new EventLog();
if (!EventLog.SourceExists("CMSMetadata_Processing"))
{
EventLog.CreateEventSource(new EventSourceCreationData("CMSMetadata_Processing", "CMSMetadata"));
}
_eventLog.Source = "CMSMetadata_Processing";
_eventLog.Log = "CMSMetadata";
}
protected override void OnStart(string[] args)
{
_eventLog.WriteEntry("In OnStart.", EventLogEntryType.Information);
}
在我安装并尝试启动服务后,它显示以下错误
错误 1053:服务没有响应启动或控制 及时提出要求
我还注意到CreateEventSource() 在事件查看器中查找时不会创建事件日志条目。
我发现 this SO post 正在讨论我面临的 1053 错误,但没有一个解决方案适合我。
我已经确认/尝试过
- 服务是按发布模式构建的。
- 由
InstallUtil和ManagedInstallerClass.InstallHelper()安装 - 框架版本和我安装的一致,其实我 尝试了 4.5.2 和 4.7.2 以防万一它真的与 框架。
- 服务作为本地系统运行。
- 配置没问题。
- 如果我删除所有与事件日志相关的代码,则服务可以成功启动。
如果服务无法正确创建事件日志条目,我认为可以,我可以提前创建条目作为解决方法。
但是,这样一来,我什至无法安装该服务。
下面的安装日志 (CMSMetadata.InstallLog) 表明无论我是否使用CreateEventSource(),安装都会以某种方式创建事件source。
Installing assembly 'C:\temp\GisSoftware\CMSMetadata\CMSMetadata.exe'.
Affected parameters are:
logtoconsole =
logfile = C:\temp\GisSoftware\CMSMetadata\CMSMetadata.InstallLog
assemblypath = C:\temp\GisSoftware\CMSMetadata\CMSMetadata.exe
Installing service CMSMetadata...
Service CMSMetadata has been successfully installed.
Creating EventLog source CMSMetadata in log Application...
Rolling back assembly 'C:\temp\GisSoftware\CMSMetadata\CMSMetadata.exe'.
Affected parameters are:
logtoconsole =
logfile = C:\temp\GisSoftware\CMSMetadata\CMSMetadata.InstallLog
assemblypath = C:\temp\GisSoftware\CMSMetadata\CMSMetadata.exe
Restoring event log to previous state for source CMSMetadata.
Service CMSMetadata is being removed from the system...
Service CMSMetadata was successfully removed from the system.
结束我的问题,在 Windows 服务中使用事件日志时我错过了什么?
【问题讨论】:
-
检查此答案,您似乎缺少 BeginInit/EndInit 调用。 stackoverflow.com/questions/8160277/…
-
@Gusman 试过了,没区别
标签: c# windows-services event-log