Multi Color Logging Class

class Logging { public enum LogType { Normal, Debug, Warning, Error, Critical }; public static void Log(Logging.LogType Type, string Message) { switch (Type) { case LogType.Normal: Console.ForegroundColor = ConsoleColor.White; break; case LogType.Warning: Console.ForegroundColor = ConsoleColor.Yellow; break; case LogType.Debug: Console.ForegroundColor = ConsoleColor.Cyan; break; case LogType.Error: Console.ForegroundColor = ConsoleColor.Red; break; case LogType.Critical: Console.ForegroundColor = ConsoleColor.Magenta; break; } Console.WriteLine("{0} {1}", GetTimestamp(), Message); File.AppendAllText("System.log", string.Format("{0}:{1} {2}" + Environment.NewLine, Type.ToString(), GetTimestamp(), Message), Encoding.UTF8); } public static String GetTimestamp(DateTime value) { return value.ToString("yyyyMMddHHmmssffff"); } public static String GetTimestamp() { return GetTimestamp(DateTime.Now); } }
console output with colors making debugging easier

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.