How to specify log file path using folder locations in Windows with log4net xml configurator?

依然范特西╮ 提交于 2019-12-22 03:19:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!