Can a 3rd party library effectively use EntLib?

Topics: General discussion, Logging Application Block
May 18, 2013 at 6:56 AM
It seems that the appropriate place to use EntLib is at the application level. However if you're a 3rd party library ISV and would like to enable your library to do logging, is it possible to still use the EntLib Logging App Block? Ironically, it is probably more of a problem if the consuming application also uses EntLib since the EntLib versions could be incompatible.

I think one solution would be to define an ILogging interface in the library and then log to it instead of a specific logging framework. The library would provide the user a way to plugin an adapter object that implements the interface (and that internally probably delegates to their choice of logging framework). Is there something in EntLib that facilitates this scenario?
May 18, 2013 at 4:47 PM
Edited May 19, 2013 at 12:38 AM
The answer is that a 3rd party library can definitely use Enterprise Library.

You are right -- the most complicated scenarios would be if the consuming application was also using Enterprise Library. This isn't really specific to Enterprise Library but for all third party libraries. There are a variety of approaches that you could take to mitigate these issues such as installing in the GAC (multiple versions can live side by side in the GAC), specifying the codebase, or a custom assembly resolver.

Of course, this all adds complication if you want to support all potential scenarios (sometimes it's hard to know how people will use your library!).

If your library is exposing the logging functionality externally (and not just using it internally for errors or tracing) then you should consider how that is done since you are imposing requirements (and dependencies) on your users. You may consider letting users to bring their own logger but that implies knowing how to use all supported loggers (plus there could be other potential issues -- what if a user disposes of the logger you are using?).

There is a project, Common.Logging, which provides a common interface (as well as adapters) that supports Enterprise Library, log4net, and NLog. That might help you since it sounds very similar to what you mention.

Randy Levy
Enterprise Library support engineer
Support How-to
May 19, 2013 at 2:14 AM
Thanks for the pointers!