Load Log4j2 configuration file programmatically

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

    Found the answer myself. Someone might find it useful.

    ConfigurationSource source = new ConfigurationSource();
    source.setLocation(logConfigurationFile);
    source.setFile(new File(logConfigurationFile));
    source.setInputStream(new FileInputStream(logConfigurationFile));
    Configurator.initialize(null, source);
    

提交回复
热议问题