2010-07-22 70 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