Throwing Nlog exceptions. A possible explanation is the absence of a zero argument and one argument. Common.Logging.Configuration.NameValueCollection constructors

I added nlog to my application and test project for it. Both are part of the same solution. Nlog works from within the application. But from test project get below exceptions:

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

      

My Nlog config 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>

      

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

      

+3


source to share


2 answers


When I looked in more detail, there was an internal exception complaining that dll dl 2.0.0 was not found. Found the solution as follows

  • Remove all packages related to reloading nlog and commons application. If packages are not removed using nuget, edit the .csproj and .packages file manually to remove any references to Commons or nlog packages logging.
  • Then I searched for the latest nlog package by typing Common.Logging.Nlog

    in the search text box. Then select the latest nlog package and it will install all other required packages to use with nlog via community logging as a dependency. As shown below: enter image description here
  • In yours, web.config

    update your adapter factory element In my case I selected 31 to update it to

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



enter image description here

PS If you get an error The configuration section cannot contain a CDATA or text element.

Then the problem must be the type in your config file.

+3


source


I had this error after moving my Common.Logging and NLog configuration from one website to another. I was missing the "dependAssembly" blocks from the assembly bindings section in the web.config file:

<assemblyBinding>
  ...
  <dependentAssembly>
    <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.2.1.0" newVersion="3.2.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
  </dependentAssembly>
</assemblyBinding>

      



Added in case it helps someone else with the same problem as me!

0


source







All Articles