我正在尝试配置基于 Topshelf 的 Windows 服务以使用 Topshelf.Log4Net 和 log4net 记录到自定义事件日志。如果我在命令行模式下运行应用程序,这很好。当我尝试使用 安装服务时BillsTestService.exe install
,我得到:
INFO Topshelf v3.1.107.0, .NET Framework v4.0.30319.18052
DEBUG Attempting to install 'BillsTestService'
Running a transacted installation.
...
Service BillsTestService has been successfully installed.
Creating EventLog source BillsTestService in log Application...
An exception occurred during the Install phase.
System.ArgumentException: Source BillsTestService already exists on the local computer.
...
at System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData)
我试过EventLog.DeleteEventSource("BillsTestService");
在安装之前在 LINQPad 中运行;成功,但后续服务安装仍然失败。
我的 log4net appender 配置是:
<appender name="ErrorEventLogAppender" type="log4net.Appender.EventLogAppender" >
<threshold value="ERROR" />
<logName value="MyCompanyServices" />
<applicationName value="BillsTestService" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %logger - %message%newline" />
</layout>
</appender>
我究竟做错了什么?
目的是让多个服务将错误记录到相同的日志名称(具有不同的应用程序名称);日志将由操作创建。