C# how to specify the appData file path in the app.config file

后端 未结 2 1267
南方客
南方客 2021-01-03 22:01

I am using log4net and I was to save the log file in the AppData file for win XP/Vista etc.

This is my app.config file so far, and I have specified the name softphon

相关标签:
2条回答
  • 2021-01-03 22:32

    User %appdata%. So your code will look like -

    <file value="%appdata%/softphone.log"/>
    
    0 讨论(0)
  • 2021-01-03 22:49

    I don't believe that you can do what you want, there is a method for custom parsing areas of the app.config file so that you could add your own token that you could replace with the correct value, but I don't see how that would work inside the log4net section.

    However, everything that is set up for log4net inside the config can also be set in code. I think you're best option would be to set the property for the appender in code just after application start.


    Ahh, never mind a quick search has revealed my ignorance. From here and here it appears that something similar to this:

    <file value="${APPDATA}\log-file.txt" />
    

    Will do what you want. I haven't tested this myself, so I'll leave my first answer up too - but I'd be interested to know if you have any luck with it.

    0 讨论(0)
提交回复
热议问题