I'm not sure how efficient this is, but it should work. log4net has an overload that accepts a Type, and you often want to name the logger after the fully qualified type name.
void Main()
{
var foo = new Bar.Foo();
ILog logger = foo.GetLogger();
}
public static class LogHelper
{
public static ILog GetLogger(this object o)
{
return LogManager.GetLogger(o.GetType());
}
}
namespace Bar
{
public class Foo {}
}
// Faking log4net
public class ILog {}
public class LogManager
{
public static ILog GetLogger(Type type)
{
Console.WriteLine("Logger: " + type.ToString());
return null;
}
}
The above prints "Logger: Bar.Foo".
P.S. Use "this.GetLogger()" if you want a logger for the current class (assuming non-static method).