【问题标题】:I'm having trouble with the settings for elmah in App.Config in a console App我在控制台应用程序中的 App.Config 中的 elmah 设置有问题
【发布时间】:2015-05-30 13:13:48
【问题描述】:

我正在尝试让 elmah 在 C# 控制台应用程序中工作。

我知道它不是为在控制台应用程序中工作而设计的,但我注意到其他人正在使用一些变通方法来做到这一点。我查看了相关帖子并找到了设置 App.Config Here 的示例,但是当我尝试插入 configSections 和 elmah 片段时,我得到了配置异常。

我在 Web 应用程序中多次使用 elmah,我想我只需要整理一下 App.Config 文件。我可能放错地方了。

这是我的 App.Config 文件(连接字符串故意散列)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
    </startup>
    <connectionStrings>
        <add name="elmah-mysql" connectionString="###############" providerName="MySQL.Data" />
    </connectionStrings>    
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-6.7.4.0" newVersion="6.7.4.0" />
          </dependentAssembly>
        </assemblyBinding>
    </runtime>
    <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"/>
        </sectionGroup>
    </configSections>
    <elmah>
        <errorLog type="Elmah.MySqlErrorLog, Elmah" connectionStringName="elmah-mysql" />
    </elmah>
</configuration>

有人发现我哪里出错了吗?

【问题讨论】:

    标签: c# .net console-application elmah


    【解决方案1】:

    重新排序您的 app.config - app.config 的第一个元素必须是 &lt;configSections&gt;。如果您阅读配置异常详细信息会很明显:)

    "每个配置文件只允许一个 &lt;configSections&gt; 元素,如果 present 必须是根元素的第一个子元素。”

    【讨论】:

    • 谢谢,看来已经解决了。是的,我想我今天过得很糟糕,从一个问题跳到另一个问题,无法正确检查消息。
    猜你喜欢
    • 2017-11-16
    • 2012-04-21
    • 2021-07-19
    • 2012-04-21
    • 2019-03-29
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多