【问题标题】:Installing Nlog Config into Eventlog with InstallNlogConfig使用 InstallNlogConfig 将 Nlog Config 安装到 Eventlog 中
【发布时间】:2013-06-05 23:54:15
【问题描述】:

我正在尝试将带有 Nlog 的日志写入 Eventlog,这是我的 Nlog.config 的一个示例

<target xsi:type="EventLog" 
    name="eventlog"
    layout="${message}"
    log="Application" 
    source="MyAppName"  />

当使用管理员权限执行InstallNlogConfig 时,会显示此错误:

NLog.NLogConfigurationException:初始化时出错 EventLog Target[eventlog] - System.IO.IOException:网络路径 没找到。

zh Microsoft.Win32.RegistryKey.Win32ErrorStatic(Int32 errorCode, 字符串 str) zh Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey, String machineName, RegistryView view) en System.Diagnostics.EventLog.GetEventLogRegKey(字符串机,布尔值 可写) zh System.Diagnostics.EventLog.FindSourceRegistration(字符串源, String machineName, Boolean readOnly, Boolean wantToCreate) en System.Diagnostics.EventLog._InternalLogNameFromSourceName(字符串 源,字符串 machineName) zh System.Diagnostics.EventLog.LogNameFromSourceName(字符串源, String machineName) zh NLog.Targets.EventLogTarget.InitializeTarget() zh c:\NLogBuild\src\NLog\Targets\EventLogTarget.cs:línea 175 en NLog.Targets.Target.Initialize(LoggingConfiguration 配置) zh c:\NLogBuild\src\NLog\Targets\Target.cs:linea 288. 2013-06-10 12:21:05.0708 信息正在关闭日志记录... 2013-06-10 12:21:05.0708 信息记录器已关闭。

【问题讨论】:

  • 您拼错了机器名称。

标签: c# .net logging nlog


【解决方案1】:

读入Nlog,Eventlog目标。

这篇文章http://berryware.wordpress.com/2009/11/06/nlog-and-windows-event-log-bug/ 更详细地解释发生了什么 我没有定义 machineName。毕竟,文档说明 machineName 无论如何都默认为本地计算机,那么为什么要设置它呢?好吧......因为如果你不这样做,那么一个名为 _operational 的布尔成员变量将保持“假”,并且需要将其设置为“真”

https://github.com/nlog/nlog/wiki/EventLog-target

machineName - 运行事件日志服务的机器的名称。默认值:.

轻松修复:

<target  name="eventlog"  xsi:type="EventLog"  layout="${longdate}|${level}|${message}"  log="Application"  source="My Source"  machineName="." />

【讨论】:

  • 这应该已经在 NLog v2.0.1 中修复了
猜你喜欢
  • 1970-01-01
  • 2013-08-13
  • 1970-01-01
  • 1970-01-01
  • 2018-08-24
  • 1970-01-01
  • 1970-01-01
  • 2015-02-21
  • 1970-01-01
相关资源
最近更新 更多