25

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

Which is a pain, the elmah file is definitely there, but something isn't happy.

What might be causing this?

ilivewithian
  • 19,476
  • 19
  • 103
  • 165

2 Answers2

43

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.

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>

The downside is that you need a config file for each section. But you often do that for web deployment projects.

Falle1234
  • 5,013
  • 1
  • 22
  • 29
  • 1
    This won't work - you need to surround etc in an tag. – UpTheCreek May 16 '11 at 10:46
  • Looks like you can't have "empty" definitions in the files. Example: errorMail.config cannot have this tag – granadaCoder Apr 11 '13 at 17:45
  • This was also valid for a wpf app when splitting the Elmah Everyewhere settings out to an external file. – chillfire Aug 25 '15 at 11:15
  • this was what I needed.. I was trying to apply to a similar sectionGroup defined this way. adding the configSource to the sub nodes worked instead! – Poat Oct 28 '22 at 16:04
1

I've added a bounty to this question as I'd also like to know the answer to this.

I need it because I use Web Deployment functionality which replaces files by their configSource attribute.

In the meantime, you could move the contents of elmah.config into your web.config, replacing the <elmah configSource="..." />.

Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114
  • Are you guyz sure that this is an issue? Check out this sample web.config from the elmah trunk.. http://code.google.com/p/elmah/source/browse/trunk/samples/web.config It looks like a supported scenario. – madaboutcode Jul 30 '10 at 02:05
  • I took my original example directly from the elamh trunk and I've used it before with no problems. Just stuck on a current project. – ilivewithian Aug 11 '10 at 11:05