无法从磁盘上的路径加载log4j 2的属性文件

时间:2017-02-09 17:06:52

标签: java web.xml log4j2

对于我在Glassfish 4.1.1中的应用程序,我正在web.xml中配置属性文件的路径:

<context-param>
        <param-name>log4jConfiguration</param-name>
        <param-value>file:///G:/log4j2.properties</param-value>
</context-param>

我的属性文件:

name=LoggingProperties
property.filename = logs
appenders = console, file

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n

appender.file.type = File
appender.file.name = LOGFILE
appender.file.fileName=${filename}/propertieslogs.log
appender.file.layout.type=PatternLayout
appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n

loggers=file
logger.file.name=com.ax
logger.file.level = debug
logger.file.appenderRefs = file
logger.file.appenderRef.file.ref = LOGFILE

rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT

每当我放置文件时,它始终显示:ERROR StatusLogger No log4j2 configuration file found. Using default configuration

1 个答案:

答案 0 :(得分:0)

您的配置看起来正确但请确保将log4j-web-2.x.jar模块添加到类路径中。 (这包含从web.xml读取配置位置的逻辑。)