1

我尝试登录多个文件,但它不起作用..

这是配置

log4j.logger.org.net.portal=DEBUG, stdout, file

log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.File=C:/default.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern="[%t] %d{HH:mm:ss,SSS} %-5p %l - %m%n"

log4j.appender.secondFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.secondFile.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.secondFile.Threshold=DEBUG
log4j.appender.secondFile.File=C:/secondfile.log
log4j.appender.secondFile.layout=org.apache.log4j.PatternLayout
log4j.appender.secondFile.layout.ConversionPattern="[%t] %d{HH:mm:ss,SSS} %-5p %l - %m%n"

log4j.additivity.myLogger=false
log4j.logger.myLogger=DEBUG, secondFile

在代码中我得到像这样的记录器:

 private static final Logger loggerSmsOrdering = Logger.getLogger("myLogger");

第二个文件中没有任何内容。怎么了?

4

2 回答 2

1

我认为您必须将 secondFile 添加到记录器 log4j.logger.org.net.portal=DEBUG, stdout, file, secondFile

于 2013-02-06T17:18:03.710 回答
0

你可以像下面这样修改

    log4j.rootLogger =DEBUG,file,secondFile

    log4j.category.myLogger=DEBUG,file 
    log4j.additivity.myLogger=false


    log4j.category.myLogger=DEBUG,secondFile
    log4j.additivity.myLogger=false

    log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.file.DatePattern='.'yyyy-MM-dd'.log'
    log4j.appender.file.Threshold=DEBUG
    log4j.appender.file.File=C:/default.log
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern="[%t] %d{HH:mm:ss,SSS} %-5p %l - %m%n"

    log4j.appender.secondFile=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.secondFile.DatePattern='.'yyyy-MM-dd'.log'
    log4j.appender.secondFile.Threshold=DEBUG
    log4j.appender.secondFile.File=C:/secondfile.log
    log4j.appender.secondFile.layout=org.apache.log4j.PatternLayout
    log4j.appender.secondFile.layout.ConversionPattern="[%t] %d{HH:mm:ss,SSS} %-5p %l - %m%n"
于 2014-11-26T13:36:12.197 回答