How to send log4j messages to Windows Events in JBoss

Our client requested that we send log events to the standard Windows Event manager. (If you’re not familiar with this, it’s My Computer -> Manage -> System Tools -> Event Viewer.)

There’s very little information on the Internets about this so I thought I’d post how to do it.

To get this working in JBoss, I needed to do two things.

  1. Copy NTEventLogAppender.dll to jboss/server/default/lib. NTEventLogAppender.dll is a part of the log4j package.
  2. Edit jboss/server/default/conf/jboss-log4j.xml and add the following.
<!-- Send events to the Windows Event Logger -->
      <appender name="WINDOWS" class="org.apache.log4j.nt.NTEventLogAppender">
         <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
         <param name="source" value="My application name"/>

         <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p %d{ISO8601} - %m%n"/>
         </layout>
   </appender>

   <root>
      <priority value="INFO"/>
      <appender-ref ref="CONSOLE"/>
      <appender-ref ref="WINDOWS"/>
   </root>
It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply