Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 688
Alexander Schmidt Avatar asked Aug 11 '13 17:08

Alexander Schmidt


1 Answers

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

like image 103
Raúl Diego Avatar answered Sep 28 '22 05:09

Raúl Diego