'Log4j - Document root element "Configuration", must match DOCTYPE root "null"

I am not able to setup log4j.xml file. I am getting below error:

"C:\Program Files\ojdkbuild\java-11-openjdk-11.0.6-1\bin\java.exe" "-javaagent:C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2021.1.1\lib\idea_rt.jar=61387:C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2021.1.1\bin" -Dfile.encoding=UTF-8 -classpath C:\development\Java\ResearchConsoleApp\target\classes;C:\Users\S765626.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar ResearchConsoleApp log4j:WARN Continuable parsing error 2 and column 30 log4j:WARN Document root element "Configuration", must match DOCTYPE root "null". log4j:WARN Continuable parsing error 2 and column 30 log4j:WARN Document is invalid: no grammar found. log4j:ERROR DOM element is - not a log4j:configuration element.

Below is my log4.xml:

 <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>

        <File name="file" fileName="logs/all.log">
            <PatternLayout>
                <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n</pattern>
            </PatternLayout>
        </File>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="console"/>
            <AppenderRef ref="file"/>
        </Root>
    </Loggers>
</Configuration>

Code:

import java.util.logging.Level;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.LogManager;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

public class ResearchConsoleApp {

   private static final Logger logger = LogManager.getLogger(ResearchConsoleApp.class);

    public static void main(String args[])  //static method
    {
     
        System.out.println("Static method");
        BasicConfigurator.configure();
        logger.info("INFO-This is my first log4j's statement");
        logger.trace("trace message log");
        logger.debug("debug message log");
        logger.info("info message log");
        logger.warn("warn message log");
        logger.error("error message log");
        logger.fatal("fatal message log");
    }
}

Below is code structure: enter image description here

Please advise to fix the issue.

Regards,



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source