2010-07-22 121 views
24

我使用ELMAH(v1.1.11517.0),我试图将配置移动到外部源。外部配置文件与ELMAH

我的配置目前看起来是这样的:

<?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运行正常,但我得到的错误

Parser Error Message: The attribute 'configSource' cannot be specified because its name starts with the reserved prefix 'config' or 'lock'. 

这是一种痛苦,该ELMAH文件肯定是存在的,但有些事不开心。

什么可能导致这种情况?

+0

已经有六个月了。你应该选择一个答案。 – jessegavin 2010-12-28 20:07:03

回答

42

你不能使用elmah的configSource元素的原因是因为elmah被定义为sectionGroup。您可以使用部分的configSource。这就是它在log4net上运行的原因。

如果你需要像丹·阿特金森在独立的配置文件中的网络部署,你可以做到以下几点:

<?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部署项目做到这一点。

+1

这将不起作用 - 您需要在标记中包围等。 – UpTheCreek 2011-05-16 10:46:14

+0

你绝对正确。我对我的例子做了修改。 – Falle1234 2011-05-16 14:24:32

+0

很好的回答。谢谢! – 2013-01-22 02:07:48

1

我添加一个赏金对这个问题,我也想知道这个问题的答案。

我需要它,因为我用的Web部署功能,它通过自己的configSource属性替换文件。

与此同时,您可以将elmah.config的内容移到您的web.config中,替换<elmah configSource="..." />

+0

你确定这是个问题吗?请查看elmah主干中的示例web.config .. http://code.google.com/p/elmah/source/browse/trunk/samples/web.config 它看起来像支持的方案。 – madaboutcode 2010-07-30 02:05:16

+4

它不起作用。 – 2010-07-30 08:28:19

+0

我直接从elamh树干上拿到了我原来的例子,之前我用过它,没有任何问题。只是停留在当前的项目上。 – ilivewithian 2010-08-11 11:05:32