繁体   English   中英

log4j正在登录控制台,但未创建日志文件

[英]log4j is logging in the console but not creating a log file

我在项目中使用log4j。 该项目运行正常,但未创建日志文件。

这是log4j.xml

<Configuration status="warn"> 
    <Properties> 
        <Property name="logHome">D:/logs</Property>
    </Properties>
    <Appenders> 
        <Console name="console" target="SYSTEM_OUT">
            <PatternLayout pattern="%-5p: %c - %m%n" />
        </Console>
        <RollingFile name="rollingFile" immediateFlush="true" fileName="${logHome}/mySample.log" filePattern="${logHome}/mySample-%i.log">
            <PatternLayout>
                <Pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} |[%t]| %-5p | %c{1} | %L - %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="5 MB" />
            </Policies>
            <DefaultRolloverStrategy max="10" />
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="org.springframework" level="info" includeLocation="true" />
        <Logger name="org.hibernate" level="info" includeLocation="true" />
        <Logger name="org.project" level="debug" includeLocation="true" />
        <Root level="info" includeLocation="true">
            <AppenderRef ref="rollingFile" />
            <AppenderRef ref="console" />
        </Root>
    </Loggers>
</Configuration>

任何帮助表示赞赏。 提前致谢。

我尝试了所有方法,但对我没有任何帮助。 最后,我不得不切换到slf4j.Logger和slf4j.LoggerFactory。 借助于此,我能够生成日志。 例:

private static final Logger LOGGER=LoggerFactory.getLogger(MyClass.class);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM