首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何成功配置Common.Logging?

如何成功配置Common.Logging?
EN

Stack Overflow用户
提问于 2013-02-12 19:41:23
回答 2查看 10.2K关注 0票数 10

我试图使用NuGet包将Common.Logging配置为在ASP.Net MVC项目中使用NLog2。根据以下URL提供的信息,我相信我的记录器配置正确,但我继续获取配置错误。

Common.Logging配置指令

NLog配置教程

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

代码语言:javascript
复制
<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.NLogLoggerFactoryAdapter,解析器错误消息:发生错误,为公共/日志记录创建配置节处理程序:无法创建类型 Common.Logging.NLog20‘

有人能就遗漏的或错误的地方提出建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-12 19:45:12

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

需要将web.config中的运行时部分更改为:

代码语言:javascript
复制
<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问题:Common.Logging / Common.Logging.NLog20 NuGet包可能出现的问题

票数 13
EN

Stack Overflow用户

发布于 2014-04-05 13:44:07

为我工作用

代码语言:javascript
复制
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog2">

而不是

代码语言:javascript
复制
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">

注意最后的20对2。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14840445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档