我在控制台应用程序中的 app.config 中对 elmah 的设置有问题



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

我知道它不是为在控制台应用程序中工作而设计的,但我注意到其他人正在使用一些变通方法。我看过相关的帖子,发现了一个在这里设置App.Config的例子,但当我尝试插入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>。如果您阅读配置异常详细信息,这将是显而易见的:)

"每个配置文件只允许一个<configSections>元素,如果present必须是根元素的第一个子元素。"

最新更新