I'm trying to use NTEventLogAppender in Tomcat log4j configuration AND in my WebApp log4j configuration:
- case A) I declare the appender just in Tomcat: it works* !
- case B) I declare the appender just in my webapp: it works* !
- case C) I declare the appender in Tomcat and in my webapp: FAILED
*it works mean that I could see related events in Windows event viewer.
My question is how to fix case C? :
- Tomcat logs are visible into the event viewer but not my webapp logs.
- NTEventLogAppender static code doesn't work from my webapp startup.
I overrides "NTEventLogAppender" java classe(following implementation) to debug:
- the first
loadLibrary("NTEventLogAppender.amd64.dll")
return"already loaded in another classloader"
error; - then the appender try to load 32bits version (
"NTEventLogAppender.dll"
) without success (cause my host is 64bits).
So I made a hack to this static part to load another DLL from TMP directory:
static {
LogLog.warn("************************************************ NTEventLogAppender");
String fileToLoad="C:\\TMP\\nt\\NTEventLogAppender.amd64.dll";
try {
System.load(fileToLoad);
LogLog.warn(String.format("load '%s' OK", fileToLoad));
} catch(java.lang.UnsatisfiedLinkError e) {
LogLog.error(String.format("unable to load %s : %s", fileToLoad, e.getMessage()), e);
}
In this case, load(...)
works but I got the following error :
java.lang.UnsatisfiedLinkError: com.mycompany.logger.NTEventLogAppender.registerEventSource(Ljava/lang/String;Ljava/lang/String;)I
at com.mycompany.logger.NTEventLogAppender.registerEventSource(Native Method)
at com.mycompany.logger.NTEventLogAppender.<init>(NTEventLogAppender.java:62)
at com.mycompany.logger.NTEventLogAppender.<init>(NTEventLogAppender.java:32)
Seems like the library is accessible but not the function. Do you have any idea to make NTEventLogAppender accessible from Tomcat and webapp ?
Library is maybe not thread safe ?
For me the appender should be declared one time for all in tomcat configuration, then as described here, I tryed to put DLL into "$CATALINA_HOME/shared/lib"
and I add this directory to my java.library.path
but it doesn't work : I got no tomcat logs event in event viewer.
Any idea on how to fix it ?