log4j2 xml configuration – Log to file and console (with different levels)
I figured it out! The <Logger> tag shouldn’t be used in this case, see Gaurang Patel’s answer for details. <?xml version=”1.0″ encoding=”UTF-8″?> <configuration status=”WARN”> <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=”logs/app.log”> <PatternLayout pattern=”%d{yyyy-mm-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} – %msg%n”/> </File> </appenders> <loggers> <root level=”debug”> <appender-ref ref=”Console” level=”info”/> … Read more