我正在使用logback 1.0.0,我的应用程序位于名为logs的根文件夹中,它包含一个名为mypp.log的日志文件,我的 logback.xml 配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>[%thread] %-5level %logger{36} - %msg%n</pattern>
</layout>
</appender>
<!--Daily rolling file appender -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>logs\myapp.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<FileNamePattern>logs\logFile.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 100MB -->
<maxFileSize>50MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- keep 30 days' worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>[%thread] %-5level %logger{36} - %msg%n</pattern>
</layout>
</appender>
<logger name="com.myapp">
<level value="debug" />
</logger>
<root>
<level value="error" />
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
它可以很好地记录到控制台,但它不会记录到文件,除非我将文件路径更改为绝对路径,请告知如何解决此问题。