简体   繁体   English

Log4j Fileappender不会创建它应该的文件

[英]Log4j Fileappender won't create the file where it should

I'm trying to log into a html file using Log4j filappender. 我正在尝试使用Log4j filappender登录html文件。 My properties file looks as follows 我的属性文件如下所示

log = C:\Log
log4j.rootLogger = DEBUG, FILE

# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/logfile.html

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.HTMLLayout
log4j.appender.FILE.layout.Title=log
log4j.appender.FILE.layout.LocationInfo=true

But it didn't create the logfile at C:\\Log so I thought i didn't work at all but i found that it creates the logfile.html and the folder as well within my .netbeans folder (C:Users\\Peter.netbeans\\7.1.1\\config\\GF3\\domain1\\Log). 但它没有在C:\\ Log创建日志文件所以我认为我根本不工作,但我发现它在我的.netbeans文件夹中创建了logfile.html和文件夹(C:Users \\ Peter。 NetBeans的\\ 7.1.1 \\ CONFIG \\ GF3 \\ DOMAIN1 \\日志)。 I'm using Netbeans 7.1.1. 我正在使用Netbeans 7.1.1。 I haven't used Log4j before and to be honest I have no idea why it does this. 我之前没有使用过Log4j,说实话我不知道为什么会这样做。 Any ideas? 有任何想法吗?

Thanks for your time 谢谢你的时间

This is the line that is defining where to save the logfile: log4j.appender.FILE.File=${log}/logfile.html 这是定义保存日志文件的位置的行: log4j.appender.FILE.File=${log}/logfile.html

If you change that to log4j.appender.FILE.File=C:/log/logfile.html Then it might work. 如果你改为log4j.appender.FILE.File=C:/log/logfile.html然后它可能会工作。

AFAIK, the first line in your config log = C:\\Log have no effect whatsoever. AFAIK,配置log = C:\\Log的第一行log = C:\\Log没有任何效果。 You can't use variables like that in your config file. 您不能在配置文件中使用这样的变量。

The single backslash in your first line could be the problem: 您的第一行中的单个反斜杠可能是问题:

log = C:\\Log log = C:\\ Log

Either use C:\\Log or C:/Log. 使用C:\\ Log或C:/ Log。

I would write the path directly into 我会直接写入路径

log4j.appender.FILE.File

without using the log = C:\\Log 不使用log = C:\\ Log

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

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