Log4j logfile error FileNotFoundException

2019-09-14 21:25发布

I am trying to write a log4j logfile using Netbeans Java. I succeded writing the log file to C:\tmp\log.txt , but for some reason i have no premission to write it at the root of my project : log.txt.

This is my log4j.properties:

log4j.rootLogger = all, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=log.txt <- failes

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=[%5p](%F:%L) %m%n
log4j.appender.FILE.Append=false

1条回答
Explosion°爆炸
2楼-- · 2019-09-14 21:56

Have you try this :

log4j.appender.FILE.File=./log.txt

. represents the current folder (usually the project root folder). Maybe the log file that you set are placed somewhere in root of your drive.


This reference may useful for you :

Where Are Your Log4j Log Files?

查看更多
登录 后发表回答