我正在开发新的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()
然后,我认为如果服务因某种原因无法正确创建事件日志条目,也许我可以提前创建该条目作为解决方法。
但是,以这种方式,我什至无法安装该服务。如下所示的安装日志(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差不多;公共...
似乎该服务默认会创建事件日志。在生成AutoLog
之前,我可能应该将Service的false
属性设置为Installer
。