General log cannot load type NLog.TargetWithLayout

I have a Wpf.net 4.0 C # project that I am trying to port using Log4Net to use NLog as the registration library for the Common.Logging Façade object. I expected this to be an easy task, but you know what they say: “Nothing is ever easy.

I used NuGet for:

  • Download NLog version 2.0.1.2.
  • Download Common.Logging.NLog version 2.0.0.
  • Download Common.Logging.NLog20 in version 2.1.2.
  • The general journal has been updated from version 2.0.0 to version 2.1.2 using NuGet.

In the app.config file, I have:

<common> <logging> <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog"> <arg key="configType" value="FILE" /> <arg key="configFile" value="~/NLog.config" /> </factoryAdapter> </logging> </common> 

... and ...

  <dependentAssembly> <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" /> </dependentAssembly> 

When I launch the application, I get an error

'Casting the constructor to the type "NameSpace.Shell.AppBootstrapper", which matches the specified binding constraints, throws an exception. "Line number" 8 "and line position" 18 ".

Internal exception:

{"Cannot load one or more of the requested types. LoaderExceptions for more information." }

Loader exception fixed, there is only one:

{"Failed to load type NLog.TargetWithLayout from the NLog assembly, Version = 2.0.1.0, Culture = neutral, PublicKeyToken = 5120e14c03d0593c.": "NLog.TargetWithLayout"}

Can anyone solve this problem or work NLog working with Common.Logging to get NLog working with Common.Logging ?

In the interest of not sending a long question, I did not include the NLog.config file, but I could if it were beneficial.

+8
c # nlog common.logging
source share
2 answers

After looking around a lot after I asked this question, and I searched many times before I asked this question. I resorted to trying to understand and hope that they can work.

What I discovered was that the Common.Logging.NLog.NLogLoggerFactoryAdapter that I used was used from the dll of Common.Logging.Nlog , and the dll has a reference to NLog 1.0.0.505 , which uses the old position for the NLog.TargetWithLayout class.

I uninstalled the Common.Logging.Nlog package using NuGet and changed the link in the app.config file to:

 <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog20"> 

Then the correct class is used, which is in the NLog 2.0.1.2 package, and allows NLog and the application to load.

I hope this helps someone else who is facing this issue. I could not find anyone who would document how to deal with this.

+15
source share

You might have installed the package Common.Logging.NLog NuGet instead of Common.Logging.Nlog20. Check out your nuget link, which can be confusing due to version 2 of CL and version 2 of NLog. Apparently you have version 2 CL, but NLogLoggerFactoryAdapter for NLog version 1.

+2
source share

All Articles