我目前正在使用Servlet 3.1编写一个Web应用程序。根据Log4j2网站
Log4j 2 "just works" in Servlet 3.0 and newer web applications.
。但每当我启动服务器(Tomcat 8.0.5)时,我都会收到错误Error processing element RandomAccessFileAppender: CLASS_NOT_FOUND
。当我使用eclipses“Open Type”查找该类时,我看到该类存在并位于org.apache.logging.log4j.core.appender包中。
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="off" packages="org.apache.logging.log4j.core.appender">
<Appenders>
<RandomAccessFileAppender name="DEFLOG" ignoreExceptions="false" fileName="${web:rootDir}/log/log.log">
<PatternLayout pattern="%d %p %C{1.} [%t] %m%n" />
</RandomAccessFileAppender>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="DEFLOG"/>
</Root>
</Loggers>
</Configuration>
此log4j2.xml文件位于src / log4j2.xml下,Log4j2-jars“log4j-api-2.0-rc1.jar”和“log4j-core-2.0-rc1.jar”位于WEB-INF下/ lib中/.