使用 elmah 的外部配置文件

发布于 2024-09-10 23:43:10 字数 1386 浏览 11 评论 0原文

我正在使用 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 文件肯定在那里,但有些东西不高兴。

可能是什么原因造成的?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃→可爱长大的 2024-09-17 23:43:10

不能对 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 部署项目中这样做。

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.

Smile简单爱 2024-09-17 23:43:10

我已经为这个问题添加了赏金,因为我也想知道这个问题的答案。

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

同时,您可以将 elmah.config 的内容移至 web.config 中,替换

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文