问题是。。。它不起作用。对这种方法有什么想法吗?下面是我试图添加到现有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(); }
好的,如果你是新的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(); }