How to configure log4j.properties file for file appenders in netbeans 6.8?

Amit Kumar picture Amit Kumar · Aug 22, 2013 · Viewed 16k times · Source

I am new to log4j and logging activities.

I have log4.properties file.

**log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n**

please suggest me how to configure it to log message into my specified file like i want it to log somewhere(i.e c:\abc.log);

let me know if you require some more inforamtion

Answer

Veronica Cornejo picture Veronica Cornejo · Aug 22, 2013

As a quick answer:

log4j.appender.FileAppender= org.apache.log4j.RollingFileAppender
log4j.appender.FileAppender.File= C:\abc.log
log4j.appender.FileAppender.MaxFileSize= 10MB
log4j.appender.FileAppender.MaxBackupIndex= 10
log4j.appender.FileAppender.layout= org.apache.log4j.PatternLayout
log4j.appender.FileAppender.layout.ConversionPattern= \#\#\#\#<%d{MMM d, yyyy h:mm:ss aa zzz}> <%p> <%c> <%X{machine}> <%X{wlsDomain}> <%t> <%X{userid}> <%X{object}> <%X{messageCode}> <%X{reqId}> <%X{reqURL}> <%m>%n
log4j.appender.FileAppender.Threshold= DEBUG

You could also need to update

log4j.rootCategory=DEBUG, FileAppender

or

log4j.rootCategory=DEBUG, stdout, FileAppender

I'd strongly suggest you to check the documentation. You seem to be using log4j 1.x . If you are using log4j 2.x, you can check here .