9

I tried using these together today, and was getting a version mismatch, as it's looking for NLog v1.

Does Common.Logging support NLog v2 yet?

If not, does anyone know if an assembly version redirect can safely be used?

UpTheCreek
  • 31,444
  • 34
  • 152
  • 221
  • did you find a solution to this - I've run into the same issue myself and am running into difficulty figuring out code changes required in Common.Logging to make it compile against NLog 2.0 – dice Jul 18 '11 at 09:52
  • 1
    @dice - not yet unfortunately, currently I'm using an earlier version of NLog – UpTheCreek Jul 21 '11 at 19:29
  • @UpTheCreek did you try assembly redirect? I checked the Common.Logging's use of NLog, it seems to be compatible with NLog2. – Kenneth Xu Jul 29 '11 at 04:24

2 Answers2

7

You can simply do assembly redirect in app.config or web.config, and CommonLogging will just work fine with NLog2 by using NLog2 as logging framework:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

The only issue is if you want to redirect NLog message to some other logging framework using CommonLogging 2.0, then there is a compatibility issue. But that is a very unusual use case.

Kenneth Xu
  • 1,514
  • 15
  • 15
  • This does not work completely. I get error when Common.Logging.NLog tries to load `NLog.TargetWithLayout`, but the class was moved to `NLog.Targets.TargetWithLayout`so loading fails. This seems to work for many people so the next thing is to find out if using MEF breaks this. – Ahe Nov 24 '11 at 09:28
  • I got this work by compiling the Common.Logging source against NLog 2.0. Changes required were quite minimal. Only change `Common.Logging.NLog.CommonLoggingTarget`s baseclass to `NLog.Targets.TargetWithLayout` and replace line 90 with `log(logger, delegate { return this.Layout.Render(logEvent); }, logEvent.Exception);`. Not a pretty solution, but works for me for now. – Ahe Nov 24 '11 at 10:17
1

If you used Nuget to get the Common.Logging.NLog library, the package will download Common.Logging v2.0 dependency. If you use Nuget to update Common.Logging, it will update it to v2.1.1.0, which will prevent the Could not load file or assembly 'NLog, Version=1.0.0.505 error.

Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406