简体   繁体   中英

Log4j2 Not Logging in External File

I am using log4j2 in my java application to log the error messages and output to console as well as an external log file. It is successfully logging the messages to console but its not logging the messages to external log file. Following is the log4j2.properties files that I am using-

status = error
name = PropertiesConfig

property.filename = <filePath>\\finderApp.log

filter.threshold.type = ThresholdFilter
filter.threshold.level = debug

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5p] %d %c - %m%n
appender.console.filter.threshold.type = ThresholdFilter
appedner.console.filter.threshold.level = error

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = <filePath>\\finderApp-bkp-%d{yyyy-MM-dd}.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d %p %c{1.} [%t] %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true

loggers = rolling

logger.rolling.name = <package for main class>
logger.rolling.level = info`enter code here`
logger.rolling.additivity = false
logger.rolling.file.appenderRefs = rolling
logger.rolling.appenderRef.rolling.ref = RollingFile

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

Is there something that I am missing in this properties file?

Try below logger configuration -

logger.xxx.name = xxx
logger.xxx.level = info
logger.xxx.additivity = false
logger.xxx.appenderRef.rolling.ref = RollingFile
logger.xxx.appenderRef.console.ref = STDOUT

rootLogger.level = error
rootLogger.additivity = false
rootLogger.appenderRef.console.ref = STDOUT
rootLogger.appenderRef.rolling.ref = RollingFile

Where xxx is root package name in which all classes and subpackages of your project are present.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM