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

☆樱花仙子☆ 提交于 2019-12-06 02:42:52

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 .

This is quite simple. Try this

log4j.rootLogger=ERROR, ROOT
# Direct log messages to a log file
#log4j.appender.ROOTLOGGER=org.apache.log4j.ConsoleAppender
log4j.appender.ROOT=org.apache.log4j.RollingFileAppender
# appends the log level to file name abc.log
log4j.appender.ROOT.File=abc.log 
log4j.appender.ROOT.MaxFileSize=1000KB
#Keep 5 old files around.
log4j.appender.ROOT.MaxBackupIndex=5
log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
#Format almost same as WebSphere's common log format.
# d date, t ist der Name des Threads, M ist Methodenname, C full qualified Classenname 
#log4j.appender.ROOT.layout.ConversionPattern=[%d] %t %C:%l %-4p - %M%n
log4j.appender.ROOT.layout.ConversionPattern=%5p [%d] [%t] %l : %m%n
# Root logger option
log4j.rootLogger=error, file, stdout

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logfile.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Struts2
log4j.logger.freemarker=ERROR
log4j.logger.com.opensymphony=ERROR
log4j.logger.com.opensymphony.xwork2.ognl=ERROR
log4j.logger.org.apache.struts2=ERROR
log4j.logger.org.apache.struts2.components=ERROR
log4j.logger.org.apache.struts2.dispatcher=ERROR
log4j.logger.org.apache.struts2.convention=ERROR

# Alfresco
log4j.logger.org.alfresco=ERROR
log4j.logger.org.apache.axis=ERROR
log4j.logger.org.apache.ws=ERROR
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!