2012-03-06 143 views
2

故障得到了以下異常Common.Logging配置。與log4net的適配器

無法獲得從配置 節「共同/日誌」 Common.Logging配置。

試圖運行下面的代碼

Common.Logging.ILog logger = Common.Logging.LogManager.GetCurrentClassLogger(); 

App.Config中:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <sectionGroup name="common"> 
     <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" /> 
    </sectionGroup> 
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> 
    </configSections> 

    <common> 
    <logging> 
     <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net"> 
     <arg key="configType" value="INLINE" /> 
     </factoryAdapter> 
    </logging> 
    </common> 

    <log4net> 
    <root> 
     <level value="ALL" /> 
     <appender-ref ref="FileAppender" /> 
    </root> 
    <appender name="FileAppender" type="log4net.Appender.FileAppender" > 
     <param name="File" value="log.txt" /> 
     <layout type="log4net.Layout.PatternLayout"> 
     <conversionPattern value="%date [%thread] %level %logger - %message%newline" /> 
     </layout> 
    </appender> 
    </log4net> 

    <connectionStrings> 
    <add name="ManagementEntities" connectionString="metadata=res://*/Model.ManagementModel.csdl|res://*/Model.ManagementModel.ssdl|res://*/Model.ManagementModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\Data\Management.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
</configuration> 

回答

0

以上配置似乎是正確的,我(除非我失去了一些東西明顯),&我當我複製在另一個項目中工作的配置時遇到類似的問題 - 事實證明,我使用.NET Framework的「Client Profile」版本作爲目標。

要更改此項,請右鍵單擊解決方案資源管理器&上的項目選擇屬性。如果「目標框架」下拉菜單爲.NET Framework X Client Profile,請將其切換爲.NET Framework X,其中X是您正在使用的.NET版本。

+0

有一個類似的問題 - 問題出現在NuGet包中。使用解決方案>管理NuGet軟件包(在Installed Packaged下)刪除了所有內容,並且只添加了Common.Logging軟件包。 – bengrine 2012-07-12 21:57:43