Include log4jna.jar, jna.jar and platform.jar in your application. If you're logging under a web server, JNA files (jna.jar and platform.jar) should be placed in a parent classloader such as Tomcat's lib directory.


log4j.appender.A.layout.ConversionPattern=%d{EEE dd MMM HH:mm:ss} - %m%n


In order to get properly formatted messages in the event log, create HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\Log4jna with the values of EventMessageFile and CategoryMessageFile pointing to the location of Win32EventLogAppender.dll (eg. c:\Program Files\MyApplication\Win32EventLogAppender.dll) and the values of TypesSupported = 7 and CategoryCount = 6. Note that unlike log4j's NTEventLogAppender, this DLL only contains message formats and you do not need to place it in the system directory.


The Log4jna value above is the name of your event source. This can be changed by defining the appender's source property.

Creating this registry key is typically done in your application's installer. Log4jna will attempt to create it if it doesn't exist, but won't know where to find the Win32EventLogAppender.dll. This will cause the Event Viewer to be confused and include a warning about not finding the message resource. Messages will still be logged and display.


Last edited Oct 14, 2010 at 12:27 PM by dblock, version 5


No comments yet.