Search code examples
javalog4jloggingevent-viewer

Log4J How to set log FOLDER (KEY) on NTEventLogAppender


I've created a appender of the type NTEventLogAppender like this:

log4j.appender.EVA=org.apache.log4j.nt.NTEventLogAppender
#log4j.appender.EVA.log=TestLog
log4j.appender.EVA.layout=org.apache.log4j.PatternLayout
log4j.appender.EVA.source=TestSource
log4j.appender.EVA.layout.ConversionPattern=[%c][%l][%p][%thread]: %m%n

As you can see, on the comented line I tried to set the log TestLog, so that the log error get stored on a specific Event Viewer Log for my application, instead of the Event Viewr default Application Log.

If I uncoment a line I an error sayng that the log property doesn't exist:

**log4j:WARN No such property [log] in org.apache.log4j.nt.NTEventLogAppender.**

Is it even possible to do this as it is using Log4Net?

Thanks


Solution

  • I don't think this is possible in log4j:

    Why can't I map my logger names to the loggers that appear in the NT Event Log when I use the NTEventLogAppender?

    Unfotunately, the logger names are hardcoded within the message resource DLL (see previous question about NTEventLogAppender), so there isn't any easy way to override those dynamically... in fact, I don't think it's possible to do it, as you'd have to modify the DLL resources for every application. Since most native applications don't use the Logger column anyway...

    Source: http://logging.apache.org/log4j/1.2/faq.html#a2.10