1
votes

I'm trying to write a log with Nlog into Eventlog, this a example of my Nlog.config

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

When executing InstallNlogConfig with Administrator rigths this show this error:

NLog.NLogConfigurationException: Error during initialization of EventLog Target[eventlog] - System.IO.IOException: The network path was not found.

en Microsoft.Win32.RegistryKey.Win32ErrorStatic(Int32 errorCode, String str) en Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey, String machineName, RegistryView view) en System.Diagnostics.EventLog.GetEventLogRegKey(String machine, Boolean writable) en System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly, Boolean wantToCreate) en System.Diagnostics.EventLog._InternalLogNameFromSourceName(String source, String machineName) en System.Diagnostics.EventLog.LogNameFromSourceName(String source, String machineName) en NLog.Targets.EventLogTarget.InitializeTarget() en c:\NLogBuild\src\NLog\Targets\EventLogTarget.cs:línea 175 en NLog.Targets.Target.Initialize(LoggingConfiguration configuration) en c:\NLogBuild\src\NLog\Targets\Target.cs:línea 288. 2013-06-10 12:21:05.0708 Info Shutting down logging... 2013-06-10 12:21:05.0708 Info Logger has been shut down.

1
You've misspelled the machine name.t3hn00b

1 Answers

2
votes

Reading into Nlog, Eventlog target.

this post http://berryware.wordpress.com/2009/11/06/nlog-and-windows-event-log-bug/ explain with more details what that happening I didn’t have machineName defined. After all, the documentation stated that machineName defaults to the local machine anyway, so why set it to anything? Well… because if you don’t then a boolean member var called _operational stays “false” and it needs to be set to “true”

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

machineName - Name of the machine on which Event Log service is running. Default: .

To easy Fix:

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