【问题标题】:How can I successfully configure Common.Logging?如何成功配置 Common.Logging?
【发布时间】:2013-02-12 19:41:23
【问题描述】:

我正在尝试使用 NuGet 包将 Common.Logging 配置为在 ASP.Net MVC 项目中使用 NLog2。根据以下 URL 提供的信息,我认为我的记录器配置正确,但我仍然遇到配置错误。

Common.Logging Configuration Instructions

NLog Configuration Tutorial

我已按照说明在 web.config 中添加了以下内容:

<configuration>
  <configSections>
      <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
      <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
      </sectionGroup>
    </configSections>
    <common>
      <logging>
        <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
            <arg key="configType" value="INLINE" />
        </factoryAdapter>
      </logging>
    </common>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <targets>
        <target name="logfile" xsi:type="file" filename="e:\logfile.txt" layout="${date:format=yyyy/MM/dd HH:mm:ss} ${message}" />
      </targets>
      <rules>
        <logger name="*" minlevel="Trace" writeTo="logfile" />
      </rules>
    </nlog> 
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
</configuration>

据我所知,这是我应该做的所有事情,但是当我尝试运行 Web 项目时出现配置错误...

解析器错误消息:为 common/logging 创建配置节处理程序时出错:无法创建类型“Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20”

任何人都可以就缺失或错误的内容提供建议吗?

【问题讨论】:

    标签: asp.net-mvc nlog common.logging


    【解决方案1】:

    问题好像是Common.Logging NuGet包(v2.0.0)添加的默认配置不对。

    web.config 中的运行时部分需要更改为以下内容:

    <dependentAssembly>
       <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.0.0.0" />
      </dependentAssembly>
    

    注意 oldVersion 值。这似乎是导致错误的原因(至少基于我在上述问题中概述的情况)。

    另请参阅此相关 GitHub 问题:Possible Issues with Common.Logging / Common.Logging.NLog20 NuGet packages

    【讨论】:

      【解决方案2】:

      使用

      为我工作
      <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog2">
      

      而不是

      <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
      

      请注意最后的 20 vs 2。

      【讨论】:

      • 嗯,我认为不存在 - 你必须打开记录程序集故障(不太确定)
      • 这不是一个非常迷信的答案,下面给出:无法创建类型'Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog2'
      猜你喜欢
      • 2011-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      相关资源
      最近更新 更多