.net – log4net Configuration Section for NUnit Test Project

configurationlog4netnetnunit

I am running NUnit with the project named AssemblyTest.nunit. The test calls another assembly which uses the log4net assembly. This is using nunit version 2.4.3 with the .net 2.0 framework.

In TestFixtureSetup I am calling log4net.Config.XmlConfigurator.Configure( ) and am getting the following error:

System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section log4net. (C:\path\to\assembly.dll.config line 7)

Is there a way to fix this without renaming the config file to 'AssemblyTest.config'?

Best Answer

I had the same problem because I forget to add the log4net definition in the configSections element.

So, if you want to put log4net-elements into the app.config, you need to include the configSections element (which tells where log4net-elements are defined) at the top of the config file.

Try it like this:

<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>
  <log4net>
  ...
  </log4net>
</configuration>
Related Topic