ProjectLighthouse/ProjectLighthouse/Logging/Loggers/ConsoleLogger.cs
Josh c86d2a11b5
Abstract config design and update logging format (#624)
* Abstract config design and update logging pattern
Also drops legacy config support

* Fix unit tests

* Make backup of config file when upgrading

* Use shared process semaphore to fix migration race conditions

* Use mutex because semaphore isn't supported

* Make startup wait for configs to load

* Move mutex to config load instead of constructor

* Add debug logging

* Make mutex static

* Change mutex name format

* Make mutex use global namespace

* Remove debug logging and fix config upgrading

* Rename lambda variable
2023-01-10 17:29:47 -06:00

29 lines
No EOL
988 B
C#

using System;
using LBPUnion.ProjectLighthouse.Extensions;
namespace LBPUnion.ProjectLighthouse.Logging.Loggers;
public class ConsoleLogger : ILogger
{
public void Log(LogLine logLine)
{
ConsoleColor oldForegroundColor = Console.ForegroundColor;
ConsoleColor logColor = logLine.Level.ToColor();
foreach (string line in logLine.Message.Split('\n'))
{
string time = DateTime.Now.ToString("MM/dd/yyyy-HH:mm:ss.fff");
string trace = "";
if (logLine.Trace.Name != null)
{
trace += logLine.Trace.Name;
if (logLine.Trace.Section != null) trace += ":" + logLine.Trace.Section;
trace = "[" + trace + "]";
}
Console.ForegroundColor = logColor;
Console.WriteLine(@$"[{time}] [{logLine.Area}/{logLine.Level.ToString().ToUpper()}] {trace}: {line}");
Console.ForegroundColor = oldForegroundColor;
}
}
}