C# 使用InstallNlogConfig将Nlog配置安装到事件日志中
我正在尝试将带有Nlog的日志写入Eventlog,这是我的Nlog.config的一个示例C# 使用InstallNlogConfig将Nlog配置安装到事件日志中,c#,.net,logging,nlog,C#,.net,Logging,Nlog,我正在尝试将带有Nlog的日志写入Eventlog,这是我的Nlog.config的一个示例 <target xsi:type="EventLog" name="eventlog" layout="${message}" log="Application" source="MyAppName" /> 使用管理员权限执行InstallNlogConfig时,会显示此错误: NLog.NLOGConfiguration异常:初始化时出错 Eve
<target xsi:type="EventLog"
name="eventlog"
layout="${message}"
log="Application"
source="MyAppName" />
使用管理员权限执行InstallNlogConfig
时,会显示此错误:
NLog.NLOGConfiguration异常:初始化时出错
EventLog目标[EventLog]-System.IO.IOException:网络路径
找不到
en Microsoft.Win32.RegistryKey.Win32 ErrorStatic(Int32 errorCode,
字符串str)en
Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey,
字符串machineName,注册表视图)en
System.Diagnostics.EventLog.GetEventLogRegKey(字符串机器,布尔值
可写)en
System.Diagnostics.EventLog.FindSourceRegistration(字符串源、,
字符串machineName,布尔值只读,布尔值wantToCreate)en
System.Diagnostics.EventLog.\u InternalLogNameFromSourceName(字符串
源,字符串machineName)en
System.Diagnostics.EventLog.LogNameFromSourceName(字符串源、,
字符串机器名)en
NLog.Targets.EventLogTarget.InitializeTarget()en
c:\NLogBuild\src\NLog\Targets\EventLogTarget.cs:línea 175 en
NLog.Targets.Target.Initialize(日志配置)en
c:\NLogBuild\src\NLog\Targets\Target.cs:línea 288。2013-06-10
12:21:05.0708信息正在关闭日志。。。2013-06-10 12:21:05.0708
信息记录器已关闭
读取Nlog,事件日志目标 这篇文章详细解释了发生了什么 我没有定义machineName。毕竟,文档说明machineName默认为本地机器,那么为什么要将其设置为任何东西呢?嗯……因为如果不这样做,那么一个名为_operational的布尔成员var将保持为“false”,并且需要设置为“true” machineName—运行事件日志服务的计算机的名称。默认值: 要轻松修复,请执行以下操作:
<target name="eventlog" xsi:type="EventLog" layout="${longdate}|${level}|${message}" log="Application" source="My Source" machineName="." />
您拼错了机器名。这应该在NLog的v2.0.1中修复