Load Log4j2 configuration file programmatically

后端 未结 8 1527
-上瘾入骨i
-上瘾入骨i 2020-12-14 14:51

I want to load Log4j2 XML configuration file programmatically from my application.

Tried this:

ConfigurationSource source = new ConfigurationSource()         


        
8条回答
  •  渐次进展
    2020-12-14 15:30

    For the newest version of log4j, here is what should work for loading an external log4j2.xml:

    String log4jConfigFile = System.getProperty("user.dir") + File.separator + "log4j2.xml";
    ConfigurationSource source = new ConfigurationSource(new FileInputStream(log4jConfigFile));
    Configurator.initialize(null, source);
    

提交回复
热议问题