xmlconsolelog4j2appenderfileappender

Very simple log4j2 XML configuration file using Console and File appender


I'd like a very simple XML configuration file with a console and a file appender using log4j2.

(The Apache Website is killing me with much Information.)


Solution

  • <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="INFO">
        <Appenders>
        
            <Console name="Console"
                     target="SYSTEM_OUT">
                <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
            </Console>
            
            <File name           ="MyFile"
                  fileName       ="all.log"
                  immediateFlush ="false"
                  append         ="false">
                <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
            </File>
            
        </Appenders>
        
        <Loggers>
            <Root level="debug">
                <AppenderRef ref="Console"/>
                <AppenderRef ref="MyFile"/>
            </Root>
        </Loggers>
    </Configuration>
    

    Notes: