I have the log4j2 jar files in my class path. Below is my Log4j2.xml. I want to write the logs to my local file "G:/test/apps.log", but I'm having two issues:
- When I run the web application, the output is printed only to the console and not to the file.
I have seen a few answers which suggested putting the Log4j2.xml in
WEB-INF/classes
. However, when I do a clean build, the file will get deleted, so where should I put the configuration file?Note : I use Tomcat : 7.0.34, Servlet 3. I have removed the reference of Log4J in Cantalina properties.
<?xml version="1.0" encoding="UTF-8"?> <configuration status="warn"> <appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/> </Console> <File name="MyFile" fileName="G:/test/apps.log"> <PatternLayout pattern="%d{yyyy-mm-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </File> </appenders> <loggers> <root level="trace"> <appender-ref ref="MyFile" level="trace" additivity="true"/> </root> </loggers> </configuration>