1

I am getting this error:

ERROR asyncRoot contains an invalid element or attribute "immediateFlush"

When I use immediateFlush attribute in appender in log4j2.xml.

<Appenders>
    <Console name="STDOUT" target="SYSTEM_OUT">
        <PatternLayout pattern="%d{dd-MM-yy HH:mm:ss} [$${ctx:instId} - $${ctx:userId}] %c.%M(%L)- %m%n" />
    </Console>

    <RollingFile name="csroot"
        fileName="${cslogs}/cslog.log" filePattern="${cslogs}/$${date:yyyy-MM}/cslog-%d{yyyy-MM-dd}-%i.log">
        <PatternLayout pattern="%d{dd-MM-yy HH:mm:ss} [$${ctx:instId} - $${ctx:userId}] %c.%M(%L)- %m%n" immediateFlush="false"/>
        <Policies>
            <SizeBasedTriggeringPolicy size="100 MB" />
        </Policies>
        <DefaultRolloverStrategy max="1000">
        </DefaultRolloverStrategy>
    </RollingFile>
</Appenders>

2 Answers2

4

Try with this modification:

<RollingFile name="csroot"
    fileName="${cslogs}/cslog.log" filePattern="${cslogs}/$${date:yyyy-MM}/cslog-%d{yyyy-MM-dd}-%i.log" immediateFlush="false">
    <PatternLayout pattern="%d{dd-MM-yy HH:mm:ss} [$${ctx:instId} - $${ctx:userId}] %c.%M(%L)- %m%n"/>
    <Policies>
        <SizeBasedTriggeringPolicy size="100 MB" />
    </Policies>
    <DefaultRolloverStrategy max="1000">
    </DefaultRolloverStrategy>
</RollingFile>

immediateFlush is not an attribute of PatternLayout.

Yasas Gunarathne
  • 833
  • 1
  • 6
  • 19
2

I know its quite an old question but might help somebody. RollingFile Appender Parameters points out the immediateFlush is the property of the appender. But you have it declared as an attribute for PatternLayout which is what is causing the error.


Sample RollingFile appender configuration:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="MyApp" packages="">
  <Appenders>
    <RollingFile name="RollingFile" fileName="logs/app.log"
                 filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz"
                 immediateFlush="false">
      <PatternLayout>
        <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      </PatternLayout>
      <Policies>
        <TimeBasedTriggeringPolicy/>
        <SizeBasedTriggeringPolicy size="250 MB"/>
      </Policies>
    </RollingFile>
  </Appenders>
  <Loggers>
    <Root level="error">
      <AppenderRef ref="RollingFile"/>
    </Root>
  </Loggers>
</Configuration>
Hegdekar
  • 1,147
  • 1
  • 13
  • 16