RollingFile Appender Log4j2 不打印行号

Ana*_*dhi 5 logging rollingfileappender line-numbers pattern-layout log4j2

我正在使用 log4j2 并具有以下依赖项::

   <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.0-rc1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.0-rc1</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我正在使用以下配置::

    <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">

    <Properties>
        <Property name="LOGGER_HOME">/logs</Property>
    </Properties>

    <Appenders>

        <RollingFile name="application" fileName="${LOGGER_HOME}/application.log"
            filePattern="${LOGGER_HOME}/application.%d{yyyy-MM-dd}_%i.log">

            <PatternLayout pattern="%d{ISO8601}{GMT} %-5p %C{2} (%F:%L) - %m%n" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="1 GB" />
            </Policies>

        </RollingFile>

        <RollingFile name="framework" fileName="${LOGGER_HOME}/em-logs/framework.log"
            filePattern="${LOGGER_HOME}/framework.%d{yyyy-MM-dd}_%i.log">

            <PatternLayout pattern="%d{ISO8601}{GMT} %-5p %C{2} (%F:%L) - %m%n" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="1 GB" />
            </Policies>
        </RollingFile>

        <Console name="out" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{ISO8601}{GMT} %-5p %C{2} (%F:%L) - %m%n" />
        </Console>

        <Async name="asyncApplication">
            <AppenderRef ref="application" />
        </Async>

        <Async name="asyncFramework">
            <AppenderRef ref="framework" />
        </Async>


    </Appenders>


    <Loggers>

        <Logger name="com.memorynotfound.logging" level="debug"
            includeLocation="true">
            <AppenderRef ref="asyncApplication" />
        </Logger>

    <Root level="debug" includeLocation="true">
            <AppenderRef ref="asyncApplication"></AppenderRef>
        </Root>

        <Logger name="org.axonframework" level="info" additivity="false"
            includeLocation="true">
            <AppenderRef ref="asyncFramework" />
        </Logger>

        <Root level="error" includeLocation="true">
            <AppenderRef ref="out" />
        </Root>

    </Loggers>


</Configuration>
Run Code Online (Sandbox Code Playgroud)

但是我在控制台上收到以下格式的日志

2015-08-20 14:29:41,613 DEBUG logging.LoggerExample (LoggerExample.java:11) - This will be printed on debug
Run Code Online (Sandbox Code Playgroud)

在滚动文件中,我得到以下模式,其中缺少行号::

2015-08-20 14:29:41,613 DEBUG ? () - This will be printed on debug
Run Code Online (Sandbox Code Playgroud)

我已经疯了,因为似乎没有任何方法可以打印行号,我也遵循了官方 log4j2 链接 Log4j2 Migration 但结果仍然与上面相同。如果有人有任何解决方案,请告诉我。

Ana*_*dhi 3

在这里我找到了解决方案:: Log4j2 AsyncLogger 与滚动文件附加程序不显示文件行号

然后我将附加程序引用更改为直接指向 RollingFile 名称<Async name>,而不是现在它正确显示行号。不确定为什么会发生这种情况,我会找到并尽快发布原因。

因此更改了以下内容::

<Logger name="com.memorynotfound.logging" level="debug"
            includeLocation="true">
            <AppenderRef ref="asyncApplication" />
        </Logger>
Run Code Online (Sandbox Code Playgroud)

<Logger name="com.memorynotfound.logging" level="debug"
        includeLocation="true">
        <AppenderRef ref="application" />
    </Logger>
Run Code Online (Sandbox Code Playgroud)