10

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?

Alexander Schmidt
  • 5,631
  • 4
  • 39
  • 79
  • 2
    Have you seen this SO question: http://stackoverflow.com/questions/17320933/set-event-id-per-log-when-writing-to-windows-event-log? – nemesv Aug 27 '13 at 19:39
  • @nemesv Yes, but where do I set the ID then? – Alexander Schmidt Aug 29 '13 at 13:24
  • 1
    It depends what do you want to have in your ID, you can use some custom values as descirbed in the linked question or you can use any of the built in renderers: https://github.com/nlog/NLog/wiki/Layout-Renderers – nemesv Aug 29 '13 at 13:27
  • @nemesv Works but is still ugly. But thats not the fault of NLog so my questions is answered so far. Feel free to add an answer and I'll mark it. – Alexander Schmidt Sep 25 '13 at 10:23

2 Answers2

7

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

Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70
Raúl Diego
  • 376
  • 3
  • 5
  • Thanks. This wasn't the problem. I just corrected my querstion above. It's all about logging to Windows EventLog. How can I tell NLog to use a certain event id. Dynamic ids would be even better. – Alexander Schmidt Oct 21 '14 at 15:08
  • @AlexanderSchmidt You can specify the `eventId`-property for the target, and provide the EventId when logging. – Rolf Kristensen Jun 16 '20 at 13:19
0

According to the NLog documentation there is an eventId tag that can be set. https://github.com/nlog/NLog/wiki/EventLog-target

<targets>
  <target xsi:type="EventLog"
          name="String"
          layout="Layout"
          machineName="String"
          source="Layout" 
          category="Layout"
          eventId="Layout"
          log="String" />
<!-- note: source is a string in NLog before 4.0 -->

</targets>
Simon The Cat
  • 604
  • 1
  • 8
  • 22