CreateEventSource不会创建事件日志条目,并且无法启动Windows服务

问题描述 投票:0回答:1

我正在开发新的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错误,但是没有一种解决方案适合我。

我已经确认/尝试过

  1. 该服务是通过发布模式构建的。
  2. 同时安装InstallUtilManagedInstallerClass.InstallHelper()
  3. 框架版本与我已经安装的版本匹配,实际上,我尝试了4.5.2和4.7.2,以防万一它确实与框架。
  4. 该服务正在作为本地系统运行。
  5. 配置没问题。
  6. 如果删除与事件日志相关的所有代码,则服务可以成功启动。

然后,我认为如果服务因某种原因无法正确创建事件日志条目,也许我可以提前创建该条目作为解决方法。

但是,以这种方式,我什至无法安装该服务。如下所示的安装日志(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服务中的事件日志的什么?

我正在开发新的Windows服务,并按照本说明中提供的步骤进行操作。在服务类中,我所做的事情与静态staticLogLog _eventLog差不多;公共...

c# windows-services event-log
1个回答
0
投票

似乎该服务默认会创建事件日志。在生成AutoLog之前,我可能应该将Service的false属性设置为Installer

© www.soinside.com 2019 - 2024. All rights reserved.