我在控制台应用程序 App.Config 中设置 elmah 时遇到问题

I'm having trouble with the settings for elmah in App.Config in a console App

我正在尝试让 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>

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

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

"Only one <configSections> element allowed per config file and if present must be the first child of the root element."