Log4j Multiple Appender Simple Example in java

# Root logger option
log4j.rootLogger=INFO, DEBUG, file,console

# Console Appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Append=true
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss,SSS} %-5p [ %M ] ( %C ) %c{1}:%L - %m%n

# File Appender
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd-HH-mm
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-ddHH:mm:ss,SSS} %-5p [ %M ] ( %C ) %c{1}:%L - %m%n
log4j.appender.file.File=C:/log/SpringMain.log
log4j.appender.file.MaxBackupIndex=10

Leave a Reply

Your email address will not be published. Required fields are marked *