How To Configure Log4J via C#
August 12, 2010
One of our products is currently using IKVM to interop with a java library. I kept seeing console warnings saying: log4j:WARN Please initialize the log4j system properly. Clearly the java library uses log4j and it is not getting initialized by my application. A customer was rightfully confused by this message so I spent a little time getting log4j setup and working. At first I was hoping I could host log4j configuration XML along side my log4net configuration but sadly that was a pipedream. I opted for this approach. public const string Log4JConfigFileName = "log4j.config"; private static void ConfigureLog4J() { if(File.Exists(Log4JConfigFileName)) { PropertyConfigurator.configureAndWatch(Log4JConfigFileName); return; } var patternLayout = new PatternLayout("%d [%t] %-5p %c - %m%n"); var consoleAppender = new ConsoleAppender(patternLayout); var fileAppender = new RollingFileAppender(patternLayout, "./logs/file-extraction-errors.log", true); fileAppender.setMaxFileSize("1MB"); fileAppender.setMaxBackupIndex(5); var rootLogger = Logger.getRootLogger(); rootLogger.setLevel(Level.ERROR); rootLogger.addAppender(fileAppender); rootLogger.addAppender(consoleAppender); } Look for…