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:
+11
-4
@@ -1,11 +1,12 @@
|
||||
using PipeShared;
|
||||
using PipeMethodCalls;
|
||||
using PipeMethodCalls;
|
||||
using PipeShared;
|
||||
using System.Diagnostics;
|
||||
using System.Xml.Linq;
|
||||
|
||||
// All output is written to an XML report next to the executable
|
||||
string reportPath = Path.Combine(AppContext.BaseDirectory, "ClientReport.xml");
|
||||
var report = new XElement("Report", new XAttribute("Started", DateTime.Now.ToString("O")));
|
||||
bool colorSwitch = false;
|
||||
|
||||
Log("Client started.");
|
||||
|
||||
@@ -52,12 +53,18 @@ lock (report)
|
||||
new XDocument(report).Save(reportPath);
|
||||
|
||||
// Thread-safe: also called from the Process.Exited event
|
||||
|
||||
void Log(string message)
|
||||
{
|
||||
lock (report)
|
||||
report.Add(new XElement("Entry", new XAttribute("Time", DateTime.Now.ToString("O")), message));
|
||||
|
||||
Console.ForegroundColor = message.Contains("Server exception") ? ConsoleColor.Red : ConsoleColor.Blue;
|
||||
if (message.Contains("Server exception"))
|
||||
{
|
||||
Console.ForegroundColor = colorSwitch ? ConsoleColor.DarkRed : ConsoleColor.Red;
|
||||
colorSwitch = !colorSwitch;
|
||||
}
|
||||
else
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine(message);
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user