.netloggingconfigurationnlog

The right way to log to EventLog using NLog


How can I avoid windows-complaining about missing descriptions for event ids when logging using NLog. When I use:

<target xsi:type="EventLog" 
        name="eventLog" 
        layout="${message}" 
        machineName="."     
        source="MyApp" 
        log="Application" />

and

<rules>
    <logger name="*" minlevel="Debug" writeTo="eventLog" />
</rules>

the entry will appear in the log. But Windows complains about missing description for the event id "0" which is right.

Do I have to do things like pointed out here to get a clean logging?


Solution

  • I know it's an old post, but the configuration should be

    <target xsi:type="EventLog" 
            name="eventLog" 
            layout="${message}"
            machineName="."     
            source="MyApp"
            log="Application"
            eventId="${event-properties:EventID:whenEmpty=0}" />
    

    and

    <rules>
        <logger name="*" minlevel="Debug" writeTo="eventLog" />
    </rules>
    

    See also: https://github.com/NLog/NLog/wiki/EventLog-target