【问题标题】:Lifestyle of NLog wrapper classNLog 包装类的生活方式
【发布时间】:2017-02-23 06:59:30
【问题描述】:

我有五个不同的记录器和一个包装器类:

internal class CommonNLogResolver : ICommonLogger
{
    private readonly NLog.Logger commonLog;
    private readonly NLog.Logger errorLog;
    private readonly NLog.Logger dataBaseLog;
    private readonly NLog.Logger logExceptionLogger;
    private readonly NLog.Logger clientLogger;

    public CommonNLoggerResolver()
    {
        commonLog = NLog.LogManager.GetLogger(Constants.CommonLog);
        errorLog = NLog.LogManager.GetLogger(Constants.ErrorLog);
        dataBaseLog = NLog.LogManager.GetLogger(Constants.DBLog);
        logExceptionLogger = NLog.LogManager.GetLogger(Constants.LogExceptionLog);
        clientLogger = NLog.LogManager.GetLogger(Constants.ReportLog);
    }
}

我查看了 NLog 中的 LogFactory.cs,因为它有一个用于记录器的缓存,所以我不知道哪种生活方式适合我的包装类。

所以我的问题是我应该注册这个类 singletontransient 还是 scope

我也在使用 SimpleInjector 进行依赖注入。

【问题讨论】:

  • 据我所知,NLog 是线程安全的,因此您可以安全地重用您的记录器。你可以让它成为单例。
  • 是的 Logger 实例是线程安全的。

标签: c# nlog simple-injector


【解决方案1】:

NLog 是线程安全的,因此您可以安全地重用您的记录器。您可以将其设为单例。

【讨论】:

    猜你喜欢
    • 2017-08-16
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多