【发布时间】:2016-01-31 04:08:39
【问题描述】:
NLog 提到了这个关于“运行缓慢”的评论,我看到其他人重复这个作为警告......好像你在使用 NLog 时应该避免使用GetCurrentClassLogger()。
我的问题是:如果您按照建议从静态字段使用 NLog,此警告是否被夸大了?它不是每个类型只运行一次...不是每个new 运行一次吗?
额外的功劳:如果这是真的,为了使这个警告有效,重复初始化一个静态字段需要什么?
/// <summary>
/// Gets the logger with the name of the current class.
/// </summary>
/// <returns>The logger.</returns>
/// <remarks>This is a slow-running method.
/// Make sure you're not doing this in a loop.</remarks>
[CLSCompliant(false)]
[MethodImpl(MethodImplOptions.NoInlining)]
public static Logger GetCurrentClassLogger()
{
return factory.GetLogger(GetClassFullName());
}
【问题讨论】: