从log4net配置部分访问appSettings配置值 [英] Accessing appSettings config values from log4net config section

查看:103
本文介绍了从log4net配置部分访问appSettings配置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道是否可以从同一文件中的log4net config部分的配置文件的appSettings部分访问键/值(不使用代码)吗?

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

例如:

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

关于这方面似乎没有任何文档,所以我不希望...如果所有其他方法都失败了,我只需将"DEV"添加到文件值中,然后将其与appSettings的Environment变量一起替换即可

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.

预先感谢

Rob

推荐答案

感谢@wageoghe的帮助.最后,我决定再次将环境值添加到配置文件中(为简单起见):

Thanks @wageoghe for your help. In the end, I decided to just add the environment value into the config file again (for simplicity):

<log4net>
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
    <file value="${APPDATA}\MyApp\DEV\MyApp.log" />
    <!-- etc -->
</log4net>

这篇关于从log4net配置部分访问appSettings配置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆