代码之家  ›  专栏  ›  技术社区  ›  Frank Schwieterman

如何在NLog中配置默认目标

  •  3
  • Frank Schwieterman  · 技术社区  · 15 年前

    问题是。。。它不起作用。对这种方法有什么想法吗?下面是我试图添加到现有logger类中的hook以创建默认目标的代码。

    public static class LegacyLogger
    {
        static LegacyLogger()
        {
            if (LogManager.Configuration == null
                || LogManager.Configuration.GetConfiguredNamedTargets().Count == 0)
            {
                if (LogManager.Configuration == null)
                {
                    LogManager.Configuration = new LoggingConfiguration();
                }
    
                //LogManager.Configuration.AddTarget("LegacyLogger", new NLog.Targets.DebuggerTarget());
                LogManager.Configuration.AddTarget("LegacyLogger", new LegacyLoggerTarget());
            }
    
            _logger = LogManager.GetCurrentClassLogger();
        }
    
    1 回复  |  直到 15 年前
        1
  •  4
  •   Frank Schwieterman    15 年前

    好的,如果你是新的NLog,我是,被告知的例子安装与安装封面有关的一切。在这种情况下,我需要:

    public static class LegacyLogger
    {
        static LegacyLogger()
        {
            if (LogManager.Configuration == null
                || LogManager.Configuration.GetConfiguredNamedTargets().Count == 0)
            {
                NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(new LegacyLoggerTarget(), LogLevel.Trace);
            }
    
            _logger = LogManager.GetCurrentClassLogger();
        }