External Config Files with elmah

坚强是说给别人听的谎言 提交于 2019-12-03 09:34:29

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.

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="..." />.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!