NLog 没有使用 LogManager.GetCurrentClassLogger 中最派生的 class
NLog is not using the most derivated class in LogManager.GetCurrentClassLogger
我有以下 class
设置。 Logger
的名称应为 *.UsedClass
而不是 *.BaseClass
。这有可能让它从 BaseClass
开始工作,还是我必须从最派生的 class 实例化 Logger
?
public abstract class BaseClass
{
public Logger Logger { get; }
protected BaseClass()
{
Logger = LogManager.GetCurrentClassLogger(GetType());
}
}
public abstract class ExtendedClass : BaseClass
{
}
public class UsedClass : ExtendedClass
{
}
来自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
.
因此它为您提供了一个名为当前 class 的记录器,并且它正在尝试使用您传入的 Type
来决定要创建的记录器类型。
如果你想获得当前class的名称的记录器,请遵循the wiki并使用:
LogManager.GetLogger(GetType().ToString())
我有以下 class
设置。 Logger
的名称应为 *.UsedClass
而不是 *.BaseClass
。这有可能让它从 BaseClass
开始工作,还是我必须从最派生的 class 实例化 Logger
?
public abstract class BaseClass
{
public Logger Logger { get; }
protected BaseClass()
{
Logger = LogManager.GetCurrentClassLogger(GetType());
}
}
public abstract class ExtendedClass : BaseClass
{
}
public class UsedClass : ExtendedClass
{
}
来自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 fromLogger
.
因此它为您提供了一个名为当前 class 的记录器,并且它正在尝试使用您传入的 Type
来决定要创建的记录器类型。
如果你想获得当前class的名称的记录器,请遵循the wiki并使用:
LogManager.GetLogger(GetType().ToString())