我正在尝试在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项目)
正如相关提问者所建议的那样,我试图将src / main / resources放在同一文件下,也试图将其放在src(源程序包)下,但是无法修复该错误。请帮助我。
答案 0 :(得分:0)
尝试将配置文件的名称更改为log4j2.xml
默认情况下,log4j2
在应用程序类路径(在src / main / resources /目录下)中搜索名称为log4j2
的文件