I want to load Log4j2 XML configuration file programmatically from my application.
Tried this:
ConfigurationSource source = new ConfigurationSource()
If you have a single main entry point, this code snippet might save you some trouble. The set property call must fire before any loggers are created. This approach works with files on the classpath.
public class TestProcess {
static {
System.setProperty("log4j.configurationFile", "log4j-alternate.xml");
}
private static final Logger log = LoggerFactory.getLogger(TestProcess.class);
}