public DisableLoggingForLevel ( NLog.LogLevel level ) : void | ||
level | NLog.LogLevel | Level to be disabled. |
return | void |
private void ConfigureLogger(NLog.LogLevel nlogLogLevel) { var config = new LoggingConfiguration(); _target = new MemoryTarget {Layout = "${level:uppercase=true}|${message}|${exception}"}; config.AddTarget("memory", _target); var loggingRule = new LoggingRule("*", NLog.LogLevel.Trace, _target); loggingRule.DisableLoggingForLevel(nlogLogLevel); config.LoggingRules.Add(loggingRule); LogManager.Configuration = config; _sut = new NLogLogProvider().GetLogger("Test"); }
private void ConfigureLogger(NLog.LogLevel nlogLogLevel) { NLogLogManager.ProviderIsAvailableOverride = true; var config = new LoggingConfiguration(); target = new MemoryTarget(); target.Layout = "${level:uppercase=true}|${message}|${exception}"; config.AddTarget("memory", target); var loggingRule = new LoggingRule("*", LogLevel.Trace, target); loggingRule.DisableLoggingForLevel(nlogLogLevel); config.LoggingRules.Add(loggingRule); NLog.LogManager.Configuration = config; sut = new NLogLogManager().GetLogger("Test"); }
private static void ChangeRuleMinLevel(LoggingRule rule, LogLevel minLevel) { /* * Based on how the LoggingLevel initializes its logging levels when given a minLevel, * but because LogLevel.MinLevel and LogLevel.MaxLevel are not publically accessible, * their current values are hardcoded. TODO: This is fragile! */ for (var i = LogLevel.Trace.Ordinal; i < minLevel.Ordinal; i++) { rule.DisableLoggingForLevel(LogLevel.FromOrdinal(i)); } for (var i = minLevel.Ordinal; i <= LogLevel.Fatal.Ordinal; i++) { rule.EnableLoggingForLevel(LogLevel.FromOrdinal(i)); } LogManager.ReconfigExistingLoggers(); }
private void SetLogLevelForRule(LoggingRule rule, LogLevel activeLogLevel) { // Reset all log levels to off for (int i = MinLogLevel; i <= MaxLogLevel; i++) { rule.DisableLoggingForLevel(LogLevel.FromOrdinal(i)); } // Enable the active log level and all levels numerically higher for (int i = activeLogLevel.GetHashCode(); i <= MaxLogLevel; i++) { rule.EnableLoggingForLevel(LogLevel.FromOrdinal(i)); } InternalLogger.Debug("*** Setting active log level for " + _logger.Name + " to " + activeLogLevel.Name); }
private void ApplyLogLevel(LoggingRule rule, IList<LogLevel> levels) { foreach (var level in rule.Levels) rule.DisableLoggingForLevel(level); foreach (var level in levels) rule.EnableLoggingForLevel(level); }