简体   繁体   English

如何解决Netbeans中“找不到Log4j 2配置文件”的问题?

[英]How to fix “No Log4j 2 configuration file found” in Netbeans?

I am trying to configure Log4j2 in Netbeans. 我试图在Netbeans中配置Log4j2。

I have used following code: 我使用了以下代码:

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"));
    }
}

When i right click and run i am getting following error message: 当我右键单击并运行时,我收到以下错误消息:

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)

currently, My project structure looks like below: (Netbeans project) 目前,我的项目结构如下所示:( Netbeans项目)

在此输入图像描述

As suggested by related questioners, I am trying to make src/main/resources and put configuration file under same and also tried to put it under src(source packages) but unable to fix that error. 正如相关提问者所建议的那样,我正在尝试创建src / main / resources并将配置文件放在相同的位置,并尝试将其置于src(源包)下但无法修复该错误。 Kindly help me. 请帮助我。

Try changing name of configuration file to log4j2.xml 尝试将配置文件的名称更改为log4j2.xml

By default, log4j2 searches for file with name log4j2 on application classpath (under src/main/resources/ directory) 默认情况下, log4j2在应用程序类路径上搜索名为log4j2文件(在src / main / resources /目录下)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM