使用elmah的外部配置文件 [英] External Config Files with elmah
问题描述
我正在使用elmah(v1.1.11517.0),并试图将配置移至外部源。
I am using elmah (v1.1.11517.0) and am trying to move the config to an external source.
我的配置当前如下所示:
My config currently looks like this:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
<section name="errorTweet" requirePermission="false" type="Elmah.ErrorTweetSectionHandler, Elmah"/>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net configSource="Settings\RobDev\log4net.config" />
<elmah configSource="Settings\RobDev\ELMAH.config" />
</configuration>
log4net很高兴并且运行良好,但是对于elmah我却报错了
log4net is happy and runs fine, however for elmah I get the error
Parser Error Message: The attribute 'configSource' cannot be specified because its name starts with the reserved prefix 'config' or 'lock'.
这很痛苦,elmah文件肯定存在,但有些不满意。
Which is a pain, the elmah file is definitely there, but something isn't happy.
可能是什么原因造成的?
What might be causing this?
推荐答案
您可以这样做的原因 t将configSource元素用于elmah是因为elmah被定义为sectionGroup。您可以在部分中使用configSource。这就是为什么它可以在log4net上工作的原因。
The reason why you can't use the configSource element for elmah is because elmah is defined as a sectionGroup. You can use the configSource on Sections. That is why it works on log4net.
如果您需要像Dan Atkinson这样的用于Web部署的单独配置文件,则可以执行以下操作:
If you need the seperate config-file for web-deployment like Dan Atkinson you could do the following:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah"/>
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
<section name="errorTweet" requirePermission="false" type="Elmah.ErrorTweetSectionHandler, Elmah"/>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net configSource="Settings\RobDev\log4net.config" />
<elmah>
<errorLog configSource="Settings\RobDev\errorLog.config" />
<errorMail configSource="Settings\RobDev\errorMail.config" />
<errorFilter configSource="Settings\RobDev\errorFilter.config" />
<errorTweet configSource="Settings\RobDev\errorTweet.config" />
<security configSource="Settings\RobDev\security.config" />
</elmah>
</configuration>
缺点是每个部分都需要一个配置文件。但是您通常会在Web部署项目中这样做。
The downside is that you need a config file for each section. But you often do that for web deployment projects.
这篇关于使用elmah的外部配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!