I'm attempting to use NuGet packages to configure Common.Logging to use NLog2 in an ASP.Net MVC project. Based on the information provided at the URLs below, I believe my loggers are configured properly, but I continue to get configuration errors.
我正在尝试使用NuGet包来配置Common.Logging以在ASP.Net MVC项目中使用NLog2。根据以下URL提供的信息,我相信我的记录器配置正确,但我仍然遇到配置错误。
Common.Logging Configuration Instructions
Common.Logging配置说明
NLog配置教程
I've added the following to web.config as per the instructions:
我按照说明将以下内容添加到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>
As far as I can tell, this is everything I should need to do but I'm getting configuration errors when I try to run the web project...
据我所知,这是我应该做的一切,但是当我尝试运行Web项目时,我遇到配置错误......
Parser Error Message: An error occurred creating the configuration section handler for common/logging: Unable to create type 'Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20'
分析器错误消息:为common / logging创建配置节处理程序时发生错误:无法创建类型'Common.Logging.NLog.NLogLoggerFactoryAdapter,Common.Logging.NLog20'
Can anyone offer suggestions on what's missing or in error?
任何人都可以提供有关缺失或错误的建议吗?
2 个解决方案
#1
13
The problem seems to be that the default configuration added by the Common.Logging NuGet package (v2.0.0) is incorrect.
问题似乎是Common.Logging NuGet包(v2.0.0)添加的默认配置不正确。
The runtime section in web.config needs to be changed to the following:
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>
Note the oldVersion value. This seems to be what was causing the error (at least based on the scenario that I outlined in the question above).
请注意oldVersion值。这似乎是造成错误的原因(至少基于我在上述问题中概述的情景)。
See also this related GitHub issue: Possible Issues with Common.Logging / Common.Logging.NLog20 NuGet packages.
另请参阅此相关的GitHub问题:Common.Logging / Common.Logging.NLog20 NuGet包可能存在的问题。
#2
1
Worked for me by using
通过使用为我工作
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog2">
instead of
代替
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
notice 20 vs 2 at the end.
最后注意20 vs 2。
#1
13
The problem seems to be that the default configuration added by the Common.Logging NuGet package (v2.0.0) is incorrect.
问题似乎是Common.Logging NuGet包(v2.0.0)添加的默认配置不正确。
The runtime section in web.config needs to be changed to the following:
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>
Note the oldVersion value. This seems to be what was causing the error (at least based on the scenario that I outlined in the question above).
请注意oldVersion值。这似乎是造成错误的原因(至少基于我在上述问题中概述的情景)。
See also this related GitHub issue: Possible Issues with Common.Logging / Common.Logging.NLog20 NuGet packages.
另请参阅此相关的GitHub问题:Common.Logging / Common.Logging.NLog20 NuGet包可能存在的问题。
#2
1
Worked for me by using
通过使用为我工作
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog2">
instead of
代替
<factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20">
notice 20 vs 2 at the end.
最后注意20 vs 2。