Load Log4j2 configuration file programmatically

后端 未结 8 1506
-上瘾入骨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

    final URL log4j = Resources.getResource("log4j2-test.xml");
    LoggerContext.getContext(false)
      .start(new XmlConfiguration(new ConfigurationSource(
        Resources.asByteSource(log4j).openStream(),
        log4j)));
    

提交回复
热议问题