路由附加程序中的Log4j2停止/关闭FileManager

时间:2019-03-11 09:10:02

标签: logging log4j2

具有以下log4j2配置

<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="DEBUG">
<Appenders>
    <Console name="ConsoleAppender" target="SYSTEM_OUT">
        <PatternLayout pattern="%highlight{%d{yyyy-MM-dd HH:mm:ss} [%T] %t %-5level %logger{36} - %msg}%n%throwable"/>
    </Console>
    <File name="FileAppender" fileName="${log4j:configParentLocation}/../test-output/logs/entire.log" immediateFlush="true" append="true">
        <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%T] %t %-5level %logger{36} - %msg%n%throwable"/>
    </File>
    <Routing name="RoutingAppender">
        <Routes pattern="$${ctx:logFilePath}">
            <!-- This route is chosen if ThreadContext has a value for logFileName.
             The value dynamically determines the name of the log file. -->
            <Route>
                <File name="TestAppender" fileName="${ctx:logFilePath}" immediateFlush="true" append="true">
                    <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%T] %t %-5level %logger{36} - %msg%n%throwable"/>
                </File>
            </Route>
             <!--This route is chosen if ThreadContext has no value for key logFileName.-->
            <Route key="$${ctx:logFilePath}">
                <File name="ConfigurationAppender" fileName="${log4j:configParentLocation}/../test-output/logs/configuration.log" immediateFlush="true" append="true">
                    <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%T] %t %-5level %logger{36} - %msg%n%throwable"/>
                </File>
            </Route>
        </Routes>
    </Routing>
</Appenders>
<Loggers>
    <Root level="DEBUG">
        <AppenderRef ref="RoutingAppender"/>
        <AppenderRef ref="ConsoleAppender"/>
        <AppenderRef ref="FileAppender"/>
    </Root>
</Loggers>
</Configuration>

我正尝试删除不再需要的RoutingAppender日志文件。但是我不能这样做,因为出现错误,记录程序FileManager锁定了该文件。

有什么主意如何在RoutingAppender中为文件调用Stop / Close FileManage?

0 个答案:

没有答案