ResetColor() публичный статический Метод

public static ResetColor ( ) : void
Результат void
Пример #1
0
        public override void Log(LogLevel level, string message)
        {
            switch (level)
            {
            case LogLevel.Fatal:
                ConsoleCrayon.BackgroundColor = ConsoleColor.Red;
                ConsoleCrayon.ForegroundColor = ConsoleColor.White;
                break;

            case LogLevel.Error:
                ConsoleCrayon.ForegroundColor = ConsoleColor.Red;
                break;

            case LogLevel.Warn:
                ConsoleCrayon.ForegroundColor = ConsoleColor.Yellow;
                break;

            case LogLevel.Info:
                ConsoleCrayon.ForegroundColor = ConsoleColor.Blue;
                break;

            case LogLevel.Debug:
                ConsoleCrayon.ForegroundColor = ConsoleColor.Green;
                break;
            }
            Console.Write(FormatLogPrompt(level));
            ConsoleCrayon.ResetColor();

            Console.Write(" ");
            Console.WriteLine(message);
        }
Пример #2
0
    public static void Commit(LogEntryType type, string message, string details, bool showUser)
    {
        if (Mute)
        {
            return;
        }

        if (message == null)
        {
            message = "";
        }

        if (type == LogEntryType.Debug && !Debugging)
        {
            return;
        }

        if (type != LogEntryType.Information || (type == LogEntryType.Information && !showUser))
        {
            var  thread_name = String.Empty;
            bool printNow    = false;
            if (Debugging)
            {
                var thread = Thread.CurrentThread;
                thread_name = thread.ManagedThreadId.ToString();
                if (thread_name == "1")
                {
                    printNow    = true;
                    thread_name = "1-GTK ";
                }
                else
                {
                    thread_name += "     ";
                }
            }

            string lineStart = string.Format("[{5}{0} {1:00}:{2:00}:{3:00}.{4:000}]", TypeString(type), DateTime.Now.Hour,
                                             DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond, thread_name);

            if (PrintAllThreads || printNow)
            {
                /*
                 * only doing this in main thread now.
                 * Less buggy and seems to have finished with ^@ and 92M messages
                 */
                switch (type)
                {
                case LogEntryType.Error:
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Red;
                    break;

                case LogEntryType.Warning:
                    ConsoleCrayon.ForegroundColor = ConsoleColor.DarkYellow;
                    break;

                case LogEntryType.Information:
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Green;
                    break;

                case LogEntryType.Debug:
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Blue;
                    break;

                case LogEntryType.SQL:
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Cyan;
                    break;

                case LogEntryType.SQLon:
                    ConsoleCrayon.BackgroundColor = ConsoleColor.DarkCyan;
                    ConsoleCrayon.ForegroundColor = ConsoleColor.White;
                    break;

                case LogEntryType.SQLoff:
                    ConsoleCrayon.BackgroundColor = ConsoleColor.DarkCyan;
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                    break;

                case LogEntryType.SQLonAlready:
                    ConsoleCrayon.BackgroundColor = ConsoleColor.DarkCyan;
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Gray;
                    break;

                case LogEntryType.ThreadStart:
                    ConsoleCrayon.BackgroundColor = ConsoleColor.Green;
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                    break;

                case LogEntryType.ThreadEnding:
                    ConsoleCrayon.BackgroundColor = ConsoleColor.Yellow;
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                    break;

                case LogEntryType.ThreadEnded:
                    ConsoleCrayon.BackgroundColor = ConsoleColor.Red;
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                    break;

                case LogEntryType.TestStart:
                    ConsoleCrayon.BackgroundColor = ConsoleColor.Blue;
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                    break;

                case LogEntryType.TestEnd:
                    ConsoleCrayon.BackgroundColor = ConsoleColor.Blue;
                    ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                    break;
                }

                Console.Write(lineStart);

                ConsoleCrayon.ResetColor();

                //print messagesOtherThreads
                //do not add to "message" because like this is better to find why crashes
                string messagesOtherThreads = LogSync.ReadAndEmpty();
                if (messagesOtherThreads != null)
                {
                    try {
                        Console.Write(messagesOtherThreads);
                    } catch (System.IndexOutOfRangeException) {
                        Console.Write("CATCHED printing messagesOtherThreads");
                    }
                }

                //print messages this thread
                if (details != null)
                {
                    message += " - " + details;
                }

                try {
                    if (type == LogEntryType.Debug)
                    {
                        Console.Write(" {0}", message);
                    }
                    else
                    {
                        Console.WriteLine(" {0}", message);
                    }
                }
                catch (System.IndexOutOfRangeException) {
                    Console.Write("CATCHED printing main thread");
                }
            }
            else
            {
                LogSync.Add(lineStart + "\n" + message);
            }
        }

        if (showUser)
        {
            OnNotify(new LogEntry(type, message, details));
        }
    }
Пример #3
0
    public static void Commit(LogEntryType type, string message, string details, bool showUser)
    {
        if (message == null)
        {
            message = "";
        }

        if (type == LogEntryType.Debug && !Debugging)
        {
            return;
        }

        if (type != LogEntryType.Information || (type == LogEntryType.Information && !showUser))
        {
            switch (type)
            {
            case LogEntryType.Error:
                ConsoleCrayon.ForegroundColor = ConsoleColor.Red;
                break;

            case LogEntryType.Warning:
                ConsoleCrayon.ForegroundColor = ConsoleColor.DarkYellow;
                break;

            case LogEntryType.Information:
                ConsoleCrayon.ForegroundColor = ConsoleColor.Green;
                break;

            case LogEntryType.Debug:
                ConsoleCrayon.ForegroundColor = ConsoleColor.Blue;
                break;

            case LogEntryType.SQL:
                ConsoleCrayon.ForegroundColor = ConsoleColor.Cyan;
                break;

            case LogEntryType.SQLon:
                ConsoleCrayon.BackgroundColor = ConsoleColor.DarkCyan;
                ConsoleCrayon.ForegroundColor = ConsoleColor.White;
                break;

            case LogEntryType.SQLoff:
                ConsoleCrayon.BackgroundColor = ConsoleColor.DarkCyan;
                ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                break;

            case LogEntryType.ThreadStart:
                ConsoleCrayon.BackgroundColor = ConsoleColor.Green;
                ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                break;

            case LogEntryType.ThreadEnding:
                ConsoleCrayon.BackgroundColor = ConsoleColor.Yellow;
                ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                break;

            case LogEntryType.ThreadEnded:
                ConsoleCrayon.BackgroundColor = ConsoleColor.Red;
                ConsoleCrayon.ForegroundColor = ConsoleColor.Black;
                break;
            }

            var thread_name = String.Empty;
            if (Debugging)
            {
                var thread = Thread.CurrentThread;
                thread_name = thread.ManagedThreadId.ToString();
                if (thread_name == "1")
                {
                    thread_name = "1-GTK ";
                }
                else
                {
                    thread_name += "     ";
                }
            }

            Console.Write("[{5}{0} {1:00}:{2:00}:{3:00}.{4:000}]", TypeString(type), DateTime.Now.Hour,
                          DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond, thread_name);

            ConsoleCrayon.ResetColor();

            if (details != null)
            {
                Console.WriteLine(" {0} - {1}", message, details);
            }
            else
            {
                if (type == LogEntryType.Debug)
                {
                    Console.Write(" {0}", message);
                }
                else
                {
                    Console.WriteLine(" {0}", message);
                }
            }
        }

        if (showUser)
        {
            OnNotify(new LogEntry(type, message, details));
        }
    }