Asp.net mvc 如何成功配置公共日志记录?

Asp.net mvc 如何成功配置公共日志记录?,asp.net-mvc,nlog,common.logging,Asp.net Mvc,Nlog,Common.logging,我正在尝试使用NuGet软件包配置Common.Logging,以便在ASP.NETMVC项目中使用NLog2。根据下面URL提供的信息,我相信我的记录器配置正确,但我仍然会遇到配置错误 我已按照说明将以下内容添加到web.config: <configuration> <configSections> <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>

我正在尝试使用NuGet软件包配置Common.Logging,以便在ASP.NETMVC项目中使用NLog2。根据下面URL提供的信息,我相信我的记录器配置正确,但我仍然会遇到配置错误

我已按照说明将以下内容添加到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.NLog.nloglogger工厂适配器,common.logging.NLog20”


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

问题似乎是Common.Logging NuGet软件包(v2.0.0)添加的默认配置不正确

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

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


.

通过使用

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

而不是

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


请注意结尾处的20对2。

Hmm我认为这不存在-您必须启用日志程序集故障(不确定)。这不是一个非常迷信的答案,下面给出:无法创建类型“Common.logging.NLog.nlogggerfactureadapter,Common.logging.NLog2”