如何使用 log4net xml 配置器在 Windows 中使用文件夹位置指定日志文件路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3338055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to specify log file path using folder locations in Windows with log4net xml configurator?
提问by Jader Dias
In my app.config I put
在我的 app.config 我把
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="%programdata%/log-file.txt"/>
but it didn't work. Any ideas?
但它没有用。有任何想法吗?
回答by Tim Lloyd
The log4net syntax for expanding environment variables is "${Variable}" e.g.
用于扩展环境变量的 log4net 语法是“${Variable}”,例如
<file value="${LOCALAPPDATA}\GojiSoft\GojiLog\log.txt" />
回答by teleute00
Resurrecting an old thread here, but I encountered the same issue and thought I'd share.
在这里复活一个旧线程,但我遇到了同样的问题,并认为我会分享。
${PROGRAMDATA}, as discussed in the comment thread of the other answer, didn't work for me (same as for OP). However, I saw a comment somewhere about it being case sensitive. Tried ${ProgramData} and sure enough, it worked fine.
${PROGRAMDATA},正如在另一个答案的评论线程中所讨论的,对我不起作用(与 OP 相同)。但是,我在某处看到了关于区分大小写的评论。尝试了 ${ProgramData} 果然,它运行良好。
回答by Leo
Use ${APPDATA} instead of ${LOCALAPPDATA}
使用 ${APPDATA} 而不是 ${LOCALAPPDATA}