Writing to the NT event logger with Log4j

[implemented and tested with log4j-1.2.6]

To run the following snippet of code, make sure the dynamic library NTEventLogAppender.dll is in your path. It can be found in jakarta-log4j-1.2.6srcjavaorgapachelog4jnt.


import org.apache.log4j.*;
import org.apache.log4j.nt.*;
public class Main
   static Logger logger = Logger.getLogger(Main.class);
   public static void main(String []args) {
      BasicConfigurator.configure(new NTEventLogAppender());
      logger.debug("debug message from log4j");
      logger.info("info message from log4j");
      logger.warn("warn message from log4j");
      logger.error("error message from log4j");
      logger.fatal("fatal message from log4j");
      logger.debug("Exception message from log4j", new Exception("Dummy exception"));