如何修复Netbeans中的“找不到Log4j 2配置文件”?

时间:2019-04-05 06:28:45

标签: java netbeans log4j log4j2 netbeans-8

我正在尝试在Netbeans中配置Log4j2。

我使用了以下代码:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class App
{
    public static void main( String[] args ) {
        Logger logger = LogManager.getRootLogger();
        logger.trace("Configuration File Defined To Be :: "+System.getProperty("log4j.configurationFile"));
    }
}

当我右键单击并运行时,我收到以下错误消息:

ERROR StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
BUILD SUCCESSFUL (total time: 2 seconds)

当前,我的项目结构如下:(Netbeans项目)

enter image description here

正如相关提问者所建议的那样,我试图将src / main / resources放在同一文件下,也试图将其放在src(源程序包)下,但是无法修复该错误。请帮助我。

1 个答案:

答案 0 :(得分:0)

尝试将配置文件的名称更改为log4j2.xml

默认情况下,log4j2在应用程序类路径(在src / main / resources /目录下)中搜索名称为log4j2的文件