namespace Holo { using System; using System.IO; using System.Text; using System.Threading; public static class Out { private static bool bwait = false; private static int CurrentWaitingMessages = 0; private static StringBuilder ErrorQueue = new StringBuilder(); private static Thread ErrorSaver = new Thread(new ThreadStart(Out.WriteAllErrors)); public static logFlags minimumImportance; internal static bool savingErrors = false; public static void PrimaryErrorWriter(string logText) { DateTime now = DateTime.Now; ErrorQueue.Append(("Event occurred : " + now.ToLongTimeString() + ":" + now.Millisecond.ToString() + "\r\n") + logText + "\r\n\r\n"); CurrentWaitingMessages++; if (!savingErrors) { StartSaving(); } WriteError("Errormessage has been added to queue"); } public static void SecundaryErrorWriter(string FatalErrorMessage) { try { StreamWriter writer = new StreamWriter(IO.workingDirectory + @"\Logs\FatalErrors.log", true); writer.Write(FatalErrorMessage); writer.Close(); } catch (Exception exception) { WriteLine(exception.ToString()); } } private static void StartSaving() { savingErrors = true; ErrorSaver.Start(); } public static void wait() { while (bwait) { Thread.Sleep(10); } } internal static void WriteAllErrors() { WriteLine("Starting checking errorqueue"); while (true) { if (ErrorQueue.Length > 0) { string str = ErrorQueue.ToString(); try { StreamWriter writer = new StreamWriter(IO.workingDirectory + @"\Logs\Exceptions.log", true); writer.Write(str.ToString()); writer.Close(); } catch (Exception exception) { WriteLine(exception.ToString()); } WriteLine("All errors where successfully saved."); ErrorQueue = new StringBuilder(); } Thread.Sleep(0x2710); } } public static void WriteBlank() { wait(); bwait = true; Console.WriteLine(); bwait = false; } public static void WriteError(string logText) { DateTime now = DateTime.Now; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("- "); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(logText); Console.ForegroundColor = ConsoleColor.Gray; } public static void WriteError(string logText, logFlags logFlag) { if (logFlag >= minimumImportance) { DateTime now = DateTime.Now; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("- "); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(logText); Console.ForegroundColor = ConsoleColor.Gray; } } public static void WriteLine(string logText) { wait(); bwait = true; DateTime now = DateTime.Now; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("- "); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(logText); Console.ForegroundColor = ConsoleColor.Gray; bwait = false; } public static void WriteLine(string logText, logFlags logFlag) { if (logFlag >= minimumImportance) { wait(); bwait = true; DateTime now = DateTime.Now; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("- "); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(logText); Console.ForegroundColor = ConsoleColor.Gray; bwait = false; } } public static void WriteLine(string logText, logFlags logFlag, ConsoleColor colorOne, ConsoleColor colorTwo) { if (logFlag >= minimumImportance) { wait(); bwait = true; DateTime now = DateTime.Now; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("- "); Console.ForegroundColor = colorTwo; Console.WriteLine(logText); Console.ForegroundColor = ConsoleColor.Gray; bwait = false; } } public static void WritePlain(string logText) { wait(); bwait = true; Console.WriteLine(logText); bwait = false; } public static void WriteSpecialLine(string logText, logFlags logFlag, ConsoleColor colorOne, ConsoleColor colorTwo, string headerHead, int headerLength, ConsoleColor headerColor) { wait(); bwait = true; DateTime now = DateTime.Now; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("] " + headerHead + " "); Console.ForegroundColor = headerColor; try { Console.Write(logText.Substring(0, headerLength)); } catch { Console.Write(logText); } Console.ForegroundColor = colorTwo; Console.WriteLine(logText.Substring(headerLength)); Console.ForegroundColor = ConsoleColor.Gray; bwait = false; } public static void WriteTrace(string logText) { } public enum logFlags { MehAction, BelowStandardAction, StandardAction, ImportantAction } } }