Add colored console output to logging

Update `Log` to write messages to the console, using red for server exceptions and blue for other messages. Preserve thread-safe XML report logging and reorder `using` directives.
This commit is contained in:
Matthias Heil
2026-11-10 10:38:20 +01:00
parent 8fbb2e2e46
commit 23c2a9ea16
+7 -3
View File
@@ -1,7 +1,7 @@
using System.Diagnostics; using ClientServerShared;
using System.Xml.Linq;
using PipeMethodCalls; using PipeMethodCalls;
using ClientServerShared; using System.Diagnostics;
using System.Xml.Linq;
// All output is written to an XML report next to the executable // All output is written to an XML report next to the executable
string reportPath = Path.Combine(AppContext.BaseDirectory, "ClientReport.xml"); string reportPath = Path.Combine(AppContext.BaseDirectory, "ClientReport.xml");
@@ -56,6 +56,10 @@ void Log(string message)
{ {
lock (report) lock (report)
report.Add(new XElement("Entry", new XAttribute("Time", DateTime.Now.ToString("O")), message)); report.Add(new XElement("Entry", new XAttribute("Time", DateTime.Now.ToString("O")), message));
Console.ForegroundColor = message.Contains("Server exception") ? ConsoleColor.Red : ConsoleColor.Blue;
Console.WriteLine(message);
Console.ResetColor();
} }
async Task BasicCallsExampleAsync() async Task BasicCallsExampleAsync()