3

I want to upgrade to Nlog version 2.1. Which version of Common Logging library should I use?

I am currently using Common Logging version 2.0 with Nlog 2.0. I replaced NLog v2.0 with 2.1 but it does not work. Any help?

I get this error - Failed obtaining configuration for Common.Logging from configuration section 'common/logging'.

Kavi
  • 33
  • 4

1 Answers1

3

You should use Common.Logging.NLog20 but you'll have to add an assembly redirect :

<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-2.1.0.0" newVersion="2.1.0.0" />
  </dependentAssembly>
</assemblyBinding>

And your common logging config should look something like this :

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

Thankfully the nuget packages for common.logging and adapters has changed (see here) You should be able to use the Common.Logging.NLog21 libarary.

Gary W
  • 1,874
  • 1
  • 14
  • 18
  • Thanks for your reply. I added Common.Logging.NLog20. However under which section of the app.config should i add the assembly binding? Also should my application refer Common.Logging.dll v 2.1 or 2.2? – Kavi Mar 06 '14 at 12:01
  • 2.1.2, the assembly bindings come under – Gary W Mar 06 '14 at 12:53
  • Hi Gary thanks i I did the above said changes but i still get the same error - Failed obtaining configuration for Common.Logging from configuration section 'common/logging' :( – Kavi Mar 10 '14 at 05:21
  • What does the inner exception say? do you have a reference to common.logging.nlog20 – Gary W Mar 10 '14 at 09:47
  • An error occurred creating the configuration section handler for common/logging: Unable to create type 'Common.Logging.NLog.NLogLoggerFactoryAdapter' – Kavi Mar 10 '14 at 11:55
  • Thanks for your help we finally used same CommonLogging.dllv2.0 & CommonLogging.Nlogdllv2.0 with and it worked – Kavi Mar 18 '14 at 06:28