3

I'm trying to get elmah working in a c# console application.

I know it wasn't designed to work in console apps but I have noticed other people are doing it using some workarounds. I've looked at related posts and found an example of setting App.Config Here, but when I try inserting the configSections and elmah fragments I get Configuration Exceptions.

I've used elmah on many occasions in Web Applications and I think I just need to sort out the App.Config file. I may have put something in the wrong place.

Here is my App.Config file (with the connection string purposely hashed out)

<?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>

Anyone spot where I've gone wrong?

Community
  • 1
  • 1
Alan Gee
  • 281
  • 1
  • 14

1 Answers1

6

Reorder your app.config - the first element of your app.config has to be <configSections>. It would be obvious if you read the configuration exception details :)

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

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89
  • Thanks, that appears to have solved it. Yes I think I was having a bad day, darting from one problem to another and can't have checked the message properly. – Alan Gee Mar 31 '15 at 11:53