0

We are in the process of building a simple logging library based on log4net. The project has some common modules for capturing unhandled exceptions etc.

The problem is we want to deploy this library to other web solutions such as umbraco and EPiServer, which both already use log4net, and use different versions. If we deploy the log4net assembly from our logging library then both umbraco and EPiServer complain about a version mismatch.

What is the best approach to get around this? I read this approach here http://www.claassen.net/geek/blog/2011/08/using-log4net-without-requiring-it-as-a-dependency.html but wasn't really sure whether this was a standardised approach?

Thanks in advance Al

higgsy
  • 1,991
  • 8
  • 30
  • 47
  • possible duplicate of [loading-multiple-versions-of-the-same-assembly](http://stackoverflow.com/questions/4451220/loading-multiple-versions-of-the-same-assembly) – k3b Apr 04 '13 at 12:30

1 Answers1

0

There's really only two approaches to this. One is to load your code in an entirely different AppDomain and take no dependencies on umbraco or EPiServer. You are then free to load whatever version of log4net you want because it will be the only version loaded. This leaves you with the issue of communicating between the AppDomain that does depend on umbraco or EPiServer and your AppDomain. This is not trivial. Looking at things like Microsoft Addin Framework (MAF) will show you why it's complicated and how to do it.

The other option is to use something like ilmerge to merge the log4net assembly in with yours. That way, whenever your code makes reference to log4net it's effectively referencing a private version of it. There's other 3rd party tools like SmartAssembly that are a little more reliable when it comes to merging assemblies. I don't think ilmerge has been worked on in a while and isn't really supported.

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
  • *"The other option is to use something like ilmerge to merge the log4net assembly in with yours."* - or of course, just pulling the log4net source code into your project and compiling it in... – MattDavey Apr 04 '13 at 14:50
  • @MattDavey Using the source directly might have some licensing issues; but, yes, that's an equivalent option. – Peter Ritchie Apr 04 '13 at 15:21
  • Thanks for your answers guys. The other option is perhaps to use something like ServiceStack.Logging https://github.com/ServiceStack/ServiceStack.Logging or Common.Logging http://netcommon.sourceforge.net/index.html but it seems with both of these you still have to deploy the log4net.dll which will again raise the dependency issue. Have I assumed right? – higgsy Apr 04 '13 at 18:23