Dot-Net

如何使用 log4net xml 配置器在 Windows 中使用文件夾位置指定日誌文件路徑?

  • June 4, 2020

在我的 app.config 我把

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
 <file value="%programdata%/log-file.txt"/>

但它沒有用。有任何想法嗎?

擴展環境變數的 log4net 語法是 “${Variable}” 例如

<file value="${LOCALAPPDATA}\GojiSoft\GojiLog\log.txt" />

在這裡復活一個舊執行緒,但我遇到了同樣的問題並認為我會分享。

$ {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} 果然,它執行良好。

引用自:https://stackoverflow.com/questions/3338055