private void DisplayMessage(WardenLoggerLevel level, string message) { Action logAction = () => Console.WriteLine($"{level.ToString().ToUpperInvariant()}: {message}"); if (!_useColors) { logAction(); return; } var foregroundColor = ConsoleColor.White; switch (level) { case WardenLoggerLevel.Trace: foregroundColor = ConsoleColor.Yellow; break; case WardenLoggerLevel.Info: foregroundColor = ConsoleColor.Green; break; case WardenLoggerLevel.Error: foregroundColor = ConsoleColor.Red; break; } Console.ForegroundColor = foregroundColor; logAction(); Console.ForegroundColor = ConsoleColor.White; }
/// <summary> /// Sets the Console Logger for Warden. /// <param name="minLevel">Minimal level of the messages that will be logged (all by default).</param> /// /// <param name="useColors">Flag determining whether to use colors for different levels (true by default).</param> /// </summary> /// <returns>Instance of fluent builder for the WardenConfiguration.</returns> public Builder WithConsoleLogger(WardenLoggerLevel minLevel = WardenLoggerLevel.All, bool useColors = true) { _configuration.WardenLoggerProvider = () => new ConsoleWardenLogger(minLevel, useColors); return(this); }
public ConsoleWardenLogger(WardenLoggerLevel minLevel = WardenLoggerLevel.All, bool useColors = true) { _minLevel = minLevel; _useColors = useColors; }
private bool DoesNotHaveMinimalLevel(WardenLoggerLevel level) { return(_minLevel < level); }