示例#1
0
        public static void Log24Bit(ConsoleColor color,
                                    bool newline,
                                    TextWriter writer,
                                    string category,
                                    string message,
                                    params object[] arg)
        {
            if (!Enabled)
            {
                return;
            }
            if (!ConsoleSwatch.EnableVT())
            {
                Log4Bit(color, newline, writer, category, message, arg);
                return;
            }

            Log24Bit(color.AsDOSColor()
                     .AsXTermColor()
                     .ToForeground(),
                     null,
                     newline,
                     writer,
                     category,
                     message,
                     arg);
        }
示例#2
0
        public static void Log24Bit(string foreground,
                                    string background,
                                    bool newLine,
                                    TextWriter writer,
                                    string category,
                                    string message,
                                    params object[] arg)
        {
            if (!Enabled)
            {
                return;
            }
            if (!ConsoleSwatch.EnableVT())
            {
                Log4Bit(ConsoleColor.Gray, newLine, writer, category, message, arg);
                return;
            }

            if (UseColor && !string.IsNullOrWhiteSpace(foreground))
            {
                writer.Write(foreground);
            }

            if (UseColor && !string.IsNullOrWhiteSpace(background))
            {
                writer.Write(background);
            }

            var output = message;

            if (arg.Length > 0)
            {
                output = string.Format(message, arg);
            }

            if (!string.IsNullOrWhiteSpace(category))
            {
                output = $"[{category}] {output}";
            }

            if (ShowTime)
            {
                output = $"{DateTime.Now.ToLocalTime().ToLongTimeString()} {output}";
            }

            writer.Write(output);

            if (UseColor && (!string.IsNullOrWhiteSpace(foreground) || !string.IsNullOrWhiteSpace(background)))
            {
                writer.Write(ConsoleSwatch.ColorReset);
            }

            if (newLine)
            {
                writer.WriteLine();
            }
        }
示例#3
0
 public static void ResetColor(TextWriter writer)
 {
     if (!ConsoleSwatch.EnableVT())
     {
         Console.ResetColor();
     }
     else
     {
         writer.Write(ConsoleSwatch.ColorReset);
     }
 }