Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
DZone MVB

Links

Social

Hiding loggers implementations using Unity

Loggers are one of most popular examples about interfaces for sure. And there are a lot of implementations of loggers. Some implementations are simple and yet powerful, some implementations may be more complex. All we have to is to select implementation we need and integrate it to our application. It seems like good idea at first place but as soon as we need to switch from one implementation to another we discover nasty dependencies we have to change in all places where we are logging. Let’s see how to avoid these dependencies.

 

NB! This blog is moved to gunnarpeipman.com

Click here to go to article

Comments

mcarpentier said:

By doing this, your log4net logger will only be linked to the Log4NetWrapper class and log4net filters won't work.

# April 21, 2009 6:21 AM

DigiMortal said:

Log4NetWrapper is the only point in *MY* code where something really knows about log4net. All logic must be carried out by this class.

As you can see I have pretty simple and thin interface for logging and I can easily change implementation of logger or logging logic.

# April 21, 2009 6:31 AM

Jacob Dvir said:

DUDE - WHY DID U PUT LOCK in your code?

this is a huge mistake and has massive impact on performance!

Log4net is thread safe by design and you don't have to use any thread safe code when accessing it!

Any calls to the logger!

Please - do not use it.

# August 4, 2009 9:38 AM

DigiMortal said:

Sorry, my bad - I was bad code copy-paste gangsta again. I try to be better in (near) future :)

# August 4, 2009 9:48 AM

Jacob Dvir said:

Reading it again, i was a bit... angry... sorry :)

# August 6, 2009 9:43 AM

DigiMortal said:

No problem, I like angry people and heavy metal :)

# August 6, 2009 10:01 AM

micro said:

So you lost the ability to config the logger, everything now from Log4NetWrapper, too bad.

# March 5, 2010 5:33 PM

DigiMortal said:

micro, you don't lose ability to conf the logger because configuration is in web.config or app.config file. There is no way to make specifics of concrete logger visible in classes where these specifics are not welcome.

# March 6, 2010 3:00 PM

weblogs.asp.net said:

Hiding loggers implementations using unity.. May I repost it? :)

# June 20, 2011 3:41 PM