NLOG给exceptionPossible解释是缺乏零arg的单ARG Common.Logging.Configuration.NameValueCollection构造 [英] Nlog giving exceptionPossible explanation is lack of zero arg and single arg Common.Logging.Configuration.NameValueCollection constructors

查看:900
本文介绍了NLOG给exceptionPossible解释是缺乏零arg的单ARG Common.Logging.Configuration.NameValueCollection构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加n日志到我的应用程序,并为它的测试项目。同样的解决方案的他们两人的一部分。从里面的应用程序n日志的作品。但是从测试项目中获得异常如下:

I added nlog to my application and the test project for it. Both of them part of the same solution. From inside application nlog works. But from test project get below exception:

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配置是如下:

My Nlog configuration is below:

    <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.congfig文件

packages.congfig file

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



推荐答案

当我接过仔细一看有一个内部异常而投诉的n日志未找到2.0.0 DLL。找到了解决方法如下:

When I took a closer look there was an inner exception which complained an nlog 2.0.0 dll was not found. Found a solution as follows


  1. 删除日志重启应用NLOG相关的所有包和commons。如果包不要被编辑的NuGet文件的.csproj删除.packages文件手动删除下议院日志记录或n日志包中的所有引用。

  2. 然后搜索最新n日志包中输入 Common.Logging.Nlog 在搜索文本框中。然后拿起最新的n日志包,它会安装所有其他所需的软件包使用n日志通过公共记录作为一个依赖使用。如下图所示:

  3. 在你的的web.config 更新您的工厂转接件在我来说,我选择了31,因此更新

  1. Delete all packages related to nlog and commons logging restart application. If the packages don't get deleted by nuget edit .csproj file and .packages file manually to remove all references to Commons logging or nlog packages.
  2. Then searched for latest nlog package as by entering Common.Logging.Nlog in search text box. Then pick the latest nlog package and it will install all other needed packages for using using nlog through commons logging as a dependency. As shown below:
  3. In your web.config update your factory adapter element In my case i selected 31 so updated it to

< factoryAdapter TYPE =Common.Logging.NLog.NLogLoggerFactoryAdapter,Common.Logging.NLog31>
<精氨酸键=configTypeVALUE =内联/>
< / factoryAdapter>

PS如果您收到错误配置节不能包含CDATA或文本元素。那么问题有可能成为你的配置文件中的类型。

P.S. If you are getting error The configuration section cannot contain a CDATA or text element. Then the problem has to be a type in your config file.

这篇关于NLOG给exceptionPossible解释是缺乏零arg的单ARG Common.Logging.Configuration.NameValueCollection构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆