Does anyone know if it's possible to access key/values from the appSettings section of a config file from the log4net config section in the same file (without using code)?
For example:
<appSettings>
<add key="Environment" value="DEV" />
<!-- etc -->
</appSettings>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="${APPDATA}\MyApp\${Environment}\MyApp.log" />
<!-- etc -->
</log4net>
There doesn't seem to be any documentation on this, so I'm not hopeful... If all else fails, I'll just add "DEV" into the file value and subst it alongside the appSettings' Environment variable.
Thanks in advance,
Rob
You should work with log4net.Util.PatternString as the file type and refer to the app setting using %appSetting{SETTING}
See code below:
<appSettings>
<add key="Environment" value="DEV" />
<!-- etc -->
</appSettings>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString"
value="${APPDATA}\MyApp\%appSetting{Environment}\MyApp.log"/>
<!-- etc -->
</log4net>
Hope this still helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With