I'm trying to write log from nlog to window's event log. This is my configuration
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<targets>
<target name="eventLog" xsi:type="EventLog" layout="${longdate} [${level:upperCase=true}] : ${message} ${exception:format=ToString}" log="Application" source="mySource"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="eventLog"/>
</rules>
</nlog>
I need to distinguish logs in event log by their levels, I need to have separate Error
and Critical
level logs
but those lines:
logger.Error("error test do eventLogu");
logger.Fatal("fatal test do eventLogu");
both write to event log with Error
level.
Is it possible to write log with Critical level using nlog?
Doesn't look like it.
If my understanding is correct, the EventLogTarget uses the EventLogEntryType Enumeration to choose the event log level. This enumeration does not have a value for critical, which is used for lower level (kernel, etc) events.
The NLog Code itself says
else if (logEvent.Level >= LogLevel.Error)
{
entryType = EventLogEntryType.Error;
}
Joe