【问题标题】:External Config Files with elmah带有 elmah 的外部配置文件
【发布时间】:2023-03-24 04:37:01
【问题描述】:

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

这可能是什么原因?

【问题讨论】:

  • 已经六个月了。你应该选择一个答案。

标签: web-config elmah configsource


【解决方案1】:

您不能为 elmah 使用 configSource 元素的原因是因为 elmah 被定义为 sectionGroup。您可以在 Sections 上使用 configSource。这就是它在 log4net 上工作的原因。

如果您像 Dan Atkinson 一样需要单独的网络部署配置文件,您可以执行以下操作:

<?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 部署项目这样做。

【讨论】:

  • 这行不通 - 你需要在 标签中包围 等。
  • 看起来文件中不能有“空”定义。示例:errorMail.config 不能有这个标签
  • 这对于 wpf 应用程序在将 Elmah Everyewhere 设置拆分到外部文件时也有效。
【解决方案2】:

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

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

与此同时,您可以将 elmah.config 的内容移动到您的 web.config 中,替换 &lt;elmah configSource="..." /&gt;

【讨论】:

  • 你确定这是个问题吗?从 elmah 中继中查看这个示例 web.config。code.google.com/p/elmah/source/browse/trunk/samples/web.config 它看起来像是受支持的场景。
  • 我直接从 elamh 后备箱中获取了我的原始示例,我之前使用过它没有任何问题。只是停留在当前的项目上。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多