Monday, December 25, 2006

Log4net and Winsor Container Integration

Inversion of Control / Depedency Injection has been floating around for several years and I got to know this design pattern through the following articles on MSDN website:
I immediately decided to adopt the pattern into my projects. I chose Castle project's Winsor container for the project I was working on. As soon as I started using Winsor container, I realized how many depedencies my program relied on implictly, especially the log4net object I had instantiated in almost every class. Following the practices recommended by Castle project, I changed the logging object as a property of a class so that Winsor container could inject the logging facility into my object at runtime.

However, my program threw out exceptions when launched. The exception message said there is a revision number mismatch in the log4net library. That is, the Winsor library I used, which is "RC2 for .NET framework 1.1", expects log4net in version 1.2.9.0, but my project referenced the log4net in 1.2.0. That caused the problem. Actually, Visual Studio gave me the warning during compiliation but I didn't notice. After I updated my log4net program reference to version 1.2.9.0, my program worked as expected and I externalized the logging dependencyin my program. That's great.

No comments: