0

I have the following class setup. The Logger should have the name *.UsedClass and not *.BaseClass. Is this possible to get it working from the BaseClass or must I instantiate the Logger from the most derivated class?

public abstract class BaseClass
{
    public Logger Logger { get; }

    protected BaseClass()
    {
        Logger = LogManager.GetCurrentClassLogger(GetType());
    }
}

public abstract class ExtendedClass : BaseClass
{

}

public class UsedClass : ExtendedClass
{

}
Dominic Jonas
  • 4,717
  • 1
  • 34
  • 77

1 Answers1

3

From the docs:

GetCurrentClassLogger(Type)

Gets a custom logger with the name of the current class. Use loggerType to pass the type of the needed Logger. The class must inherit from Logger.

So it's giving you a logger with the name of the current class, and it's trying to use the Type you pass in to decide what type of logger to create.

If you want to get a logger with the name of the current class, follow the wiki and use:

LogManager.GetLogger(GetType().ToString())
canton7
  • 37,633
  • 3
  • 64
  • 77