Set Event ID per log when writing to Windows Event Log

1,022 views
Skip to first unread message

cocowalla

unread,
Jun 26, 2013, 9:04:08 AM6/26/13
to nlog-...@googlegroups.com
I've got the EventLog target set up like so:

<target xsi:type="EventLog"
  name="EventLog"
  layout="${longdate:universalTime=true}|${level:uppercase=true}|${logger}|${message}"
  source="MyApp"
  log="Application" />


Now, obviously not all my events will have the same ID, so I want to set event ID on a per message basis, rather than setting a static ID in the config. I believe this should work:

var logger = LogManager.GetCurrentClassLogger();

var logEvent = new LogEventInfo(LogLevel.Warn, logger.Name, "Test message");
logEvent.Properties.Add("EventID", 4444);

logger.Log(logEvent);

..but my events always have event ID set to 0. Anyone know how to get this working?

cocowalla

unread,
Jun 26, 2013, 1:02:23 PM6/26/13
to nlog-...@googlegroups.com
Figured it out - you have to use a layout in the `eventId` property of the target:

<target xsi:type="EventLog"
  name="EventLog"
  layout="${longdate:universalTime=true}|${level:uppercase=true}|${logger}|${message}"
  source="MyApp"
  eventId="${event-properties:EventID}"
  log="Application" />



Mauricio Sougarret

unread,
Jun 30, 2013, 4:38:59 AM6/30/13
to nlog-...@googlegroups.com
Thank you a lot. I've been more than four hours try to resolve the exact same problem!!
Reply all
Reply to author
Forward
0 new messages