log4j2无法创建文件

时间:2018-11-02 14:19:48

标签: log4j2

我正在尝试在Java桌面应用程序中写入错误以记录文件,但无法正常工作。

错误是:

  

2018-11-02 21:10:27,975 AWT-EventQueue-0错误无法创建文件   C:UsersNhanDesktopPRJ311JDBCsrc hanloggerlogging.log   java.io.IOException:文件名,目录名或卷标签   语法不正确

这是我的配置:

status = error
name = PropertiesConfig
property.filename = C:\Users\Nhan\Desktop\PRJ311\JDBC
filters = threshold
filter.threshold.type = ThresholdFilter
filter.threshold.level = debug
appenders = rolling
appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = debug-backup-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L -  %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 20
loggers = rolling
logger.rolling.name = nhan.views
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRef.rolling.ref = RollingFile

1 个答案:

答案 0 :(得分:0)

反斜杠在每个the Java Properties class的属性文件中具有特殊含义。您需要通过向每个反斜杠添加另一个反斜杠来逃避反斜杠:

 C:\\Users\\Nhan\\Desktop\\PRJ311\\JDBC