static ConsoleColor LogTypeToConsoleColor(NetLogType type) { if (type == NetLogType.Debug) { return(ConsoleColor.White); } else if (type == NetLogType.Verbose) { ChangeVerboseColor = !ChangeVerboseColor; return(ChangeVerboseColor ? ConsoleColor.Gray : ConsoleColor.DarkGray); } else if (type == NetLogType.Important) { return(ConsoleColor.Green); } else if (type == NetLogType.Warning) { return(ConsoleColor.Yellow); } else if (type == NetLogType.Error) { return(ConsoleColor.Red); } else { return(ConsoleColor.White); } }
/// <summary> /// Writes a message to the console. /// </summary> /// <param name="message">The message to write.</param> /// <param name="type">The type of message to write.</param> public static void Write(string message, NetLogType type) { lock (lk) { // Console Log if (LogMethod.HasFlag(NetLoggerMethod.Console)) { ConsoleColor lastColor = Console.ForegroundColor; Console.ForegroundColor = LogTypeToConsoleColor(type); Console.WriteLine(message); Console.ForegroundColor = lastColor; } // IDE Output Log if (LogMethod.HasFlag(NetLoggerMethod.IDEOutput)) { Debug.WriteLine(message); } // Event Log if (LogMethod.HasFlag(NetLoggerMethod.Event) && MessageLogged != null) { MessageLogged(new NetLog(message, type)); } } }
/// <summary> /// Creates a new NetLog. /// </summary> /// <param name="message">The log's message.</param> /// <param name="type">The log's type.</param> public NetLog(string message, NetLogType type) { this.Message = message; this.Type = type; }