how to configure log file path to current working target directory in log4j2 xml format

12,003

Here is an example configuration provided by log4j2 doc

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
  <Appenders>
    // This section represents your properties
    <File name="MyFile" fileName="./target/test-classes/example.log">
      <PatternLayout>
        <Pattern>%m%n</Pattern>
      </PatternLayout>
    </File>
  </Appenders>
  <Loggers>
    <Root level="error">
      <AppenderRef ref="MyFile"/>
    </Root>
  </Loggers>
</Configuration>

https://logging.apache.org/log4j/2.x/manual/appenders.html#FileAppender

Share:
12,003

Related videos on Youtube

Madhuri Haritha
Author by

Madhuri Haritha

Updated on June 04, 2022

Comments

  • Madhuri Haritha
    Madhuri Haritha almost 2 years

    Iam migrating my project from log4j 1.2.17 to 2.10.0.

    I have following file appender configuartion in 1.2.17 properties format.

    log4j.appender.example=org.apache.log4j.FileAppender
    log4j.appender.example.file=./target/test-classes/example.log
    log4j.appender.example.layout=org.apache.log4j.PatternLayout
    log4j.appender.example.layout.ConversionPattern=%m%n
    

    how to configure the above target folder file configuration in log4j2 xml format.

    Thanks in advance.