代码之家  ›  专栏  ›  技术社区  ›  ilivewithian

使用elmah的外部配置文件

  •  25
  • ilivewithian  · 技术社区  · 16 年前

    我正在使用elmah(v1.1.11517.0)并尝试将配置移到外部源。

    我的配置当前如下所示:

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

    是什么原因造成的?

    2 回复  |  直到 16 年前
        1
  •  42
  •   Falle1234    15 年前

    不能为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>
    

        2
  •  1
  •   Dan Atkinson    16 年前

    我给这个问题加了一个悬赏,因为我也想知道这个问题的答案。

    我需要它,因为我使用Web部署功能,它用configSource属性替换文件。

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

    推荐文章