问题
In my app.config I put
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="%programdata%/log-file.txt"/>
but it didn't work. Any ideas?
回答1:
The log4net syntax for expanding environment variables is "${Variable}" e.g.
<file value="${LOCALAPPDATA}\GojiSoft\GojiLog\log.txt" />
回答2:
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.
回答3:
Use ${APPDATA} instead of ${LOCALAPPDATA}
来源:https://stackoverflow.com/questions/3338055/how-to-specify-log-file-path-using-folder-locations-in-windows-with-log4net-xml