25

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

これは苦痛です。elmah ファイルは間違いなくそこにありますが、何かが不満です。

何が原因でしょうか?

4

2 に答える 2

42

elmah に configSource 要素を使用できない理由は、elmah が sectionGroup として定義されているためです。セクションで configSource を使用できます。そのため、log4net で動作します。

Dan Atkinson のような Web 展開用に個別の構成ファイルが必要な場合は、次のようにします。

<?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 デプロイメント プロジェクトではそうします。

于 2010-08-02T13:36:20.793 に答える
1

これに対する答えも知りたいので、この質問に報奨金を追加しました。

ファイルを configSource 属性で置き換える Web 配置機能を使用しているため、必要です。

それまでの間、elmah.config の内容を web.config に移動して、<elmah configSource="..." />.

于 2010-07-27T09:51:13.937 に答える