Пример #1
0
        public ConsoleColor GetColorOrDefault(char key)
        {
            // TODO: Potentially abstract the default values to a static instance

            // Check null
            if (ForegroundColors == null)
            {
                return(ConsoleColor.White);
            }

            // Check if entry exists
            return(ForegroundColors.TryGetValue(key, out var output) ? output : ConsoleColor.White);
        }
Пример #2
0
        /// <inheritdoc />
        public override void Write(LogInfo logInfo, string messageTemplate, params object[] logParameters)
        {
            if (!BackgroundColors.TryGetValue(logInfo.LogLevel, out var backgroundColor))
            {
                backgroundColor = ConsoleColor.Black;
            }

            if (!ForegroundColors.TryGetValue(logInfo.LogLevel, out var foregroundColor))
            {
                foregroundColor = ConsoleColor.White;
            }
            // Make sure the colors don't mix, as the write is not atomic.
            lock (_lock)
            {
                Console.BackgroundColor = backgroundColor;
                Console.ForegroundColor = foregroundColor;
                Console.Write(Format(logInfo, messageTemplate, logParameters));
                Console.ResetColor();
            }
        }