Common.Logging config exception
Asked Answered
A

1

11

I'm getting the following exception when I try to call

var log = LogManager.GetLogger(this.GetType());

A first chance exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll

An unhanded exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll

Additional information: Failed obtaining configuration for Common.Logging from configuration section 'common/logging'.

This is a .NET 4 application with references to

  • log4net.dll
  • Common.Logging.dll
  • Common.Logging.log4net.dll

my app.config has the following:

<?xml version="1.0"?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
    <configSections>
        <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
    </configSections>
    <common>
        <logging>
            <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
                <arg key="level" value="ALL" />
                <arg key="showLogName" value="true" />
                <arg key="showDataTime" value="true" />
                <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
            </factoryAdapter>
        </logging>
    </common>
</configuration>    

I'm trying to call like so:

var log = LogManager.GetLogger(this.GetType());
log.Debug(m => m("testing"));

What am I missing?

Aldo answered 21/7, 2011 at 16:46 Comment(0)
P
29

It runs ok if you remove element startup from your config.

EDIT: Instead of removing, just move the startup element after configsections.

Passable answered 21/7, 2011 at 17:13 Comment(5)
Whoa! Indeed, remove that and it works. extra points if you state 'why'.Banal
I believe it's because of how the configuration schema is validated or loaded.Passable
nice one! This answer is still valid for VS2012/.Net 4.5, Common.Logging 2.1.1, Common.Logging.Log4Net 2.0.0 and log4net 1.2.10Winonawinonah
From the docs on the configSections element: "If this element is in a configuration file, it must be the first child element of the <configuration> element."Njord
And if the problem persists? :( Any other ideas?Estivate

© 2022 - 2024 — McMap. All rights reserved.