如何配置log4j2.xml以记录多个文件?

时间:2017-07-10 01:49:00

标签: logging mule

这里我尝试配置log4j2.xml文件,以便它可以记录到2个文件,请参阅下面的配置。但是,我只获得一个日志文件 integrated_application.log ,另一个日志文件 my_application.log 根本没有记录。我错过了任何配置吗?或者,我要添加另一个AsyncRoot吗?谢谢你的帮助!

<Appenders>
    <RollingFile name="file" fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}my_application.log" filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}my_application-%i.log">
        <PatternLayout pattern="%d [%t] %-5p %c - %m%n" />
        <SizeBasedTriggeringPolicy size="10 MB" />
        <DefaultRolloverStrategy max="10" />
    </RollingFile>

    <RollingFile name="file" fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}integrated_applications.log" filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}integrated_applications-%i.log">
        <PatternLayout pattern="%d [%t] %-5p %c - %m%n" />
        <SizeBasedTriggeringPolicy size="10 MB" />
        <DefaultRolloverStrategy max="10" />
    </RollingFile>
</Appenders>

<Loggers>
    <!-- CXF is used heavily by Mule for web services-->
    <AsyncLogger name="org.apache.cxf" level="WARN" />
    <!--Apache Commons tend to make a lot of noise which can clutter the log-->
    <AsyncLogger name="org.apache" level="WARN" />
    <!-- Reduce startup noise -->
    <AsyncLogger name="org.springframework.beans.factory" level="WARN" />
    <!-- Mule classes -->
    <AsyncLogger name="org.mule" level="INFO" />
    <AsyncLogger name="com.mulesoft" level="INFO"/>
    <!-- Reduce DM verbosity -->
    <AsyncLogger name="org.jetel" level="WARN" />
    <AsyncLogger name="Tracking" level="WARN" />

    <AsyncRoot level="INFO">
        <AppenderRef ref="file" />
    </AsyncRoot>
</Loggers>

1 个答案:

答案 0 :(得分:2)

RollingFile的姓名更改为file1file2。在AppenderRef中将其用作

<AsyncRoot level="INFO">
    <AppenderRef ref="file1" />
    <AppenderRef ref="file2" />
</AsyncRoot>

希望这有帮助。