Migrating from Log4Net

Topics: Logging Application Block
Jul 20, 2008 at 4:11 PM
Edited Jul 20, 2008 at 4:11 PM
I was looking into migrating from Log4Net to the Logging application block and after looking around, I can't seem to find the best way to adapt how we use Log4Net.

We've had each class have its own instance of ILog via LogManager.GetLogger(Type) so that when we call _log.Error, _log.Exception, etc, the type is added to the output.  I realize that this can be added as a facade around the Logger static instance inserted into the LogEntry, but I wasn't sure the best way to do that.

It seems that Categories need to be pre-defined in config so that wouldn't be ideal if it's arbitrary per type.  Has anyone written any nice facade's around Logger (to provide a few simple methods Error, Warning, Info, etc, with overloads like message, params, severity while filling in the LogEntry behhind-the-scenes)?  Where would the best place to put in the extra type info?

Thanks
Jul 21, 2008 at 3:41 AM
I created a library like this for my project.  You can download the source code here.  There is a CodeSmith template that I used to generate the main Logger class. I then used ReSharper to refactor out an interface.  My first implementation used all static methods, but I recently changed to non-static methods, so I could use dependency injection to validate logging was being called.

A couple of notes, I the main logging class, Logger, the main write method will attempt to suspend impersonation before writing the log message. I have attempted to prevent the logging from throwing errors.  If error is thrown during logging, the error is written to Debug output.

Phil

onovotny wrote:
I was looking into migrating from Log4Net to the Logging application block and after looking around, I can't seem to find the best way to adapt how we use Log4Net.

We've had each class have its own instance of ILog via LogManager.GetLogger(Type) so that when we call _log.Error, _log.Exception, etc, the type is added to the output.  I realize that this can be added as a facade around the Logger static instance inserted into the LogEntry, but I wasn't sure the best way to do that.

It seems that Categories need to be pre-defined in config so that wouldn't be ideal if it's arbitrary per type.  Has anyone written any nice facade's around Logger (to provide a few simple methods Error, Warning, Info, etc, with overloads like message, params, severity while filling in the LogEntry behhind-the-scenes)?  Where would the best place to put in the extra type info?

Thanks