Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing appSettings config values from log4net config section

Tags:

log4net

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

like image 404
Rob Avatar asked Mar 26 '13 16:03

Rob


1 Answers

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 :)

like image 185
Oren Ben-Meir Avatar answered Oct 08 '22 09:10

Oren Ben-Meir