Getting a Logger with C# and Log4Net

I use log4net at work all the time. When I first started using it years ago, I got a reference to the logger by passing in my class name. But if you have to refactor code, you may forget to change the name that you used for your logger. This can cause trouble later while debugging. Below is a simple way to get a logger.

private static readonly ILog log = LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s