How to specify Event Category when writing to EventLog?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to specify Event Category when writing to EventLog?

tempid
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
  <targets>
    <target xsi:type="EventLog" name="eventlog" layout="[${logger}] ${message}" log="Application" category="${message}" source="MyApp"  />
  </targets>
  <rules>
    <logger name="*" minlevel="Trace" writeTo="EventLog" />
  </rules>
</nlog>

If I remove the category, it works. But if I specify category="${message}" or category="${Test}", it fails. How do I write custom text in it?
Reply | Threaded
Open this post in threaded view
|

Re: How to specify Event Category when writing to EventLog?

Jason LaFlair
Administrator
The event category is a strange monster.

It's limited to being a System.Int16 so NLog converts it (or at least tries to).  When you are specifying your layouts I'm guessing the conversion of those are causing an exception to be thrown and to be swallowed (unless you have nlog exceptions enabled).

Here's a 'short' (haha) article that quite a view blogs reference when asked how to setup Event Log categories.

http://www.drdobbs.com/customizing-event-log-categories/184405714