C# · 12月 27, 2021

c# – Common.Logging配置异常

当我尝试调用时,我收到以下异常 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’.

这是一个.NET 4应用程序

> log4net.dll
> Common.Logging.dll
> Common.Logging.log4net.dll

我的app.config具有以下内容:

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

我试图像这样打电话:

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

我失踪了什么

解决方法 如果您从配置中删除元素启动,则运行正常.

编辑:而不是删除,只需移动启动元素后配置.