here is in C#:
private static readonly ILog log = LogManager.GetLogger(typeof (MyClass));
Not only in C# but another language i saw the same.. any thought?
here is in C#:
private static readonly ILog log = LogManager.GetLogger(typeof (MyClass));
Not only in C# but another language i saw the same.. any thought?
It's private because other classes should not access MyClass
' log.
It's static
because it doesn't depend on the class instance. (And so that it can be used by static
methods)
So that the field isn't inherited by your sub-classes.
Take this example:
class BaseFoobar
{
public static readonly ILog log = LogManager.GetLogger(typeof(BaseFoobar));
}
class SpecializedFoobar : BaseFoobar
{
public void Whatever()
{
log.Error("I exploded");
}
}
If SpecializedFoobar
's Whatever()
function is ever called the co-responding log would be invalid:
[MyApp.BaseFoobar]: ERROR: I exploded