Alternate server exception log colors

Use red and dark red alternation for server exceptions, green for other messages, and reorder the related using directives.
This commit is contained in:
Matthias Heil
2026-11-10 11:06:10 +01:00
parent ae723b9bea
commit 3fe7fa42e5
+11 -4
View File
@@ -1,11 +1,12 @@
using PipeShared; using PipeMethodCalls;
using PipeMethodCalls; using PipeShared;
using System.Diagnostics; using System.Diagnostics;
using System.Xml.Linq; 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");
var report = new XElement("Report", new XAttribute("Started", DateTime.Now.ToString("O"))); var report = new XElement("Report", new XAttribute("Started", DateTime.Now.ToString("O")));
bool colorSwitch = false;
Log("Client started."); Log("Client started.");
@@ -52,12 +53,18 @@ lock (report)
new XDocument(report).Save(reportPath); new XDocument(report).Save(reportPath);
// Thread-safe: also called from the Process.Exited event // Thread-safe: also called from the Process.Exited event
void Log(string message) 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));
if (message.Contains("Server exception"))
Console.ForegroundColor = message.Contains("Server exception") ? ConsoleColor.Red : ConsoleColor.Blue; {
Console.ForegroundColor = colorSwitch ? ConsoleColor.DarkRed : ConsoleColor.Red;
colorSwitch = !colorSwitch;
}
else
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(message); Console.WriteLine(message);
Console.ResetColor(); Console.ResetColor();
} }