/// <summary> /// Writes the given text to the console with a timestamp and the calling method. Writes in gray by default. /// </summary> /// <param name="text">The text to write.</param> /// <param name="color">The color to use for the text.</param> /// <param name="name">The calling method.</param> public static void WriteLine(string text, ConsoleColor color = ConsoleColor.Gray, [CallerMemberName] string name = "") { if ((PrintingFlags & ConsolePrintingFlags.Print) == 0) { return; } text = (PrintingFlags & ConsolePrintingFlags.RemoveMarkdown) != 0 ? text.RemoveAllMarkdown() : text; text = (PrintingFlags & ConsolePrintingFlags.RemoveDuplicateNewLines) != 0 ? text.RemoveDuplicateNewLines() : text; var time = (PrintingFlags & ConsolePrintingFlags.LogTime) != 0; var call = (PrintingFlags & ConsolePrintingFlags.LogCaller) != 0; if (time && call) { text = $"[{DateTime.Now.ToString("HH:mm:ss")}] [{name}]: {text}"; } else if (time) { text = $"[{DateTime.Now.ToString("HH:mm:ss")}]: {text}"; } else if (call) { text = $"[{name}]: {text}"; } lock (_MessageLock) { var oldColor = Console.ForegroundColor; Console.ForegroundColor = color; Console.WriteLine(text); Console.ForegroundColor = oldColor; if (!WrittenLines.TryGetValue(name, out var list)) { WrittenLines.TryAdd(name, list = new ConcurrentBag <string>()); } list.Add(text); } }
public void WriteLine(string line) { WrittenLines.Add(line); }
public void WriteLine(string output) => WrittenLines.Add(output);