【问题标题】:Common.Logging configuration. Troubles with log4net adapterCommon.Logging 配置。 log4net 适配器的问题
【发布时间】:2012-03-06 20:59:15
【问题描述】:

遇到以下异常

Common.Logging 从配置获取配置失败 “通用/日志记录”部分。

在尝试运行下一个代码时

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

应用程序配置:

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

【问题讨论】:

    标签: .net log4net app-config log4net-configuration


    【解决方案1】:

    上面的配置对我来说似乎是正确的(除非我遗漏了一些明显的东西),当我复制在另一个项目中工作的配置时,我遇到了类似的问题 - 结果我使用的是“客户端配置文件” .NET Framework 版本作为目标。

    要更改此设置,请右键单击解决方案资源管理器上的项目并选择属性。如果“目标框架”下拉列表为 .NET Framework X Client Profile,请将其切换为 .NET Framework X,其中 X 是您正在使用的 .NET 版本。

    【讨论】:

    • 有一个类似的问题 - 问题出在 NuGet 包中。使用解决方案 > 管理 NuGet 包(在 Installed Packaged 下)删除了所有内容,并且只添加了 Common.Logging 包。
    猜你喜欢
    • 2011-04-09
    • 2011-02-17
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 2011-10-10
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    相关资源
    最近更新 更多