Log4j2.xml not writing logs into the logfile.log

Completed

I have a log4j2.xml and when I complete executing selenium TC, the logfile.log gets created with 0 bytes. Tried changing the content on log4j2.xml but not successful. Does anyone has any idea what is wrong?

Find below the content in log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
 
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
</Console>
 
<RollingFile name="RollingFile" filename="logfile.log"
filepattern="${logPath}/%d{YYYYMMddHHmmss}-fargo.log">
<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
<Policies>
<SizeBasedTriggeringPolicy size="100 MB" />
</Policies>
<DefaultRolloverStrategy max="20" />
</RollingFile>
 
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console" />
<AppenderRef ref="RollingFile" />
</Root>
</Loggers>
</Configuration>

If I use below content  then it gives 'main ERROR Unknown object "root" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored: try nesting it inside one of: ["Appenders", "Loggers", "Properties", "Scripts", "CustomLevels"].' error

<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration
    xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

    <appender name="fileAppender"
        class="org.apache.log4j.FileAppender">

        <param name="Threshold" value="INFO" />

        <param name="File" value="logfile.log" />

        <layout class="org.apache.log4j.PatternLayout">

            <param name="ConversionPattern" value="%d %-5p [%c{1}] %m %n" />

        </layout>

    </appender>

    <root>

        <level value="INFO" />

        <appender-ref ref="fileAppender" />

    </root>

</log4j:configuration>

Please sign in to leave a comment.