Thang Pham Thang Pham -4 years ago 113
Java Question

How to make log4j record to a file and print to console

I can make the log to go the console but I cant seem to make it go to a log file. Here is my

properties
file.

log4j.rootLogger=DEBUG, LOG , stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p %d{d/MM/yy HH:mm:ss}:%m%n
# log4j.appender.LOG.Threshold=INFO

log4j.appender.LOG=org.apache.log4j.RollingFileAppender
log4j.appender.LOG.File=C:\dev\harry\data\logs\core.log
log4j.appender.LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.LOG.Append=true
log4j.appender.LOG.layout.ConversionPattern=%5p %d{d/MM/yy HH:mm:ss}:%m%n
# log4j.appender.LOG.Threshold=INFO

Answer Source

The problem is that your single \ should be \\. This is true in most properties files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download