Please see https://svn.apache.org/repos/asf/logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java or https://svn.apache.org/repos/asf/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java
Ralph On Feb 13, 2013, at 3:34 AM, Thainan Frota wrote: > I tried, but could not. > > Could you please send an example? > > > Atenciosamente, > > -- > Thainan Frota > LinkedIn: thainanfrota > Facebook: thainanfrota > Twitter: @thainanfrota > Telefone: +55 75 9141 0429 | E-mail: [email protected] > > > 2013/2/13 Ralph Goers <[email protected]> > Can you use the Configurator class? > > Ralph > > On Feb 12, 2013, at 7:16 PM, Thainan Frota wrote: > >> I'm trying to use an XML configuration file for Log4j2 that is embedded in >> my Java application, but is not working. >> >> The code: >> >> ConfigurationSource source = new >> ConfigurationSource(Main.class.getResourceAsStream("/in/gunbound/prelauncher/server/log4j2/log4j2.xml")); >> ConfigurationFactory factory = (ConfigurationFactory) >> XMLConfigurationFactory.getInstance().getConfiguration(source); >> ConfigurationFactory.setConfigurationFactory(factory); >> >> The error: >> >> > Exception in thread "main" java.lang.ClassCastException: >> > org.apache.logging.log4j.core.config.XMLConfiguration cannot be cast >> > to org.apache.logging.log4j.core.config.ConfigurationFactory at >> > in.gunbound.prelauncher.server.Main.main(Main.java:62) >> >> Can anyone help me please? >> >> Note. The xml file is within my JAR, ie, I created a package to store it >> because I do not want the settings file log4j2 is exposed to the user. >> >> Atenciosamente, >> >> -- >> Thainan Frota >> LinkedIn: thainanfrota >> Facebook: thainanfrota >> Twitter: @thainanfrota >> Telefone: +55 75 9141 0429 | E-mail: [email protected] > >
