示例#1
0
        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;
        }
示例#2
0
            /// <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);
            }
示例#3
0
 public ConsoleWardenLogger(WardenLoggerLevel minLevel = WardenLoggerLevel.All, bool useColors = true)
 {
     _minLevel  = minLevel;
     _useColors = useColors;
 }
示例#4
0
 private bool DoesNotHaveMinimalLevel(WardenLoggerLevel level)
 {
     return(_minLevel < level);
 }