获取未知类型" org.apache.log4j.PropertyConfigurator"在netbeans

时间:2015-01-31 06:41:02

标签: java netbeans log4j

我正在尝试使用netbeans ide实现log4j。

我的Java代码是

public class MyClass {

    final static Logger logger = Logger.getLogger(MyClass.class.getName());
     static {
        File file = new File("log4j.properties");
        System.out.print(file.getAbsolutePath());
        PropertyConfigurator.configure(file.getAbsolutePath()); --- line 5
    }
    }

问题是代码执行成功没有任何错误但是没有创建日志文件。当我将netbeans置于调试模式时,我正在跟踪内部监视变量控制台“Unknown type”org.apache.log4j.PropertyConfigurator“。在上面代码的第5行。我试图在我的WEB-INF中包含log4j.properties文件/ classes文件夹但它没有被创建。我不确定是什么问题。

my log4j.properties file look like 

#Root logger option
log4j.rootLogger=DEBUG, stdout

#Redirect log messages to console
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Rirect log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender   
log4j.appender.file.File=/home/resources/log4j.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n


I am getting logs in console but no log4j.log file get created. Any idea?

0 个答案:

没有答案