NLog给出异常可能的解释是缺少零个arg和单个arg Common.Logging.Configuration.NameValueCollection构造函数

帕格

我将NLog添加到我的应用程序和测试项目中。它们都属于同一解决方案。NLog从应用程序内部运行。但是从测试项目中得到以下异常:

Unable to create instance of type Common.Logging.NLog.NLogLoggerFactoryAdapter. Possible explanation is lack of zero arg and single arg Common.Logging.Configuration.NameValueCollection constructors

我的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.1.2.0" newVersion="2.1.2.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>    
    <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" internalLogFile="C:\git\foo\logs\nlog.log" internalLogLevel="Warn">
            <extensions>
              <add assembly="NLog.RollbarSharp" />
            </extensions>
            <targets>
              <target xsi:type="RollbarSharp" name="Rollbar" />
              <target xsi:type="File" name="FileLog" layout="${date:format=yyyy-MM-dd HH\:mm\:ss}|${level:uppercase=true}|${logger}|${message}${onexception:${exception:format=tostring}}" encoding="iso-8859-2" fileName="C:\git\foo\logs\foo-${shortdate}.log" archiveFileName="C:\git\foo\logs\archives\foo-${shortdate}.{#####}.log" archiveAboveSize="5000000" archiveNumbering="Sequence" concurrentWrites="true" keepFileOpen="false" />
            </targets>
            <rules>
              <logger name="*" minLevel="Trace" writeTo="FileLog" />
              <logger name="*" minLevel="Error" writeTo="Rollbar" />
            </rules>
          </nlog>

packages.config文件

<packages>
  <package id="Common.Logging" version="2.3.1" targetFramework="net45" />
  <package id="Common.Logging.NLog20" version="2.3.1" targetFramework="net45" />
  <package id="NLog" version="3.1.0.0" targetFramework="net45" />
  <package id="NLog.RollbarSharp" version="0.1.2.0" targetFramework="net45" />
  <package id="RollbarSharp" version="0.3.1.0" targetFramework="net45" />
</packages>

帕格

当我仔细查看时,发现有一个内部异常,抱怨找不到nlog 2.0.0 dll。找到了如下解决方案

  1. 删除与nlog和commons logging重新启动应用程序有关的所有软件包。如果软件包没有被nuget删除,请手动编辑.csproj文件和.packages文件,以删除对Commons日志记录或nlog软件包的所有引用。
  2. 然后,通过Common.Logging.Nlog在搜索文本框中输入来搜索最新的nlog包然后选择最新的nlog软件包,它将安装所有其他需要的软件包,以通过公共日志将nlog用作依赖项来使用nlog。如下所示:在此处输入图片说明
  3. 在您的web.config更新中,您的工厂适配器元素在我的情况下,我选择了31,因此将其更新为

    <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog31"> <arg key="configType" value="INLINE" /> </factoryAdapter>

在此处输入图片说明

PS如果出现错误The configuration section cannot contain a CDATA or text element.,则问题必须出在配置文件中。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档