internal override void Write(DateTime timeStamp, Logger.LogLevels lvl, Thread currentExecThread, string className, string msg) { string threadName = currentExecThread.Name ?? currentExecThread.ManagedThreadId.ToString(); switch (lvl) { case Logger.LogLevels.FATAL: HighLight("FATAL", ConsoleColor.White, ConsoleColor.Red); break; case Logger.LogLevels.ERROR: HighLight("ERROR", ConsoleColor.Red, ConsoleColor.Black); break; case Logger.LogLevels.WARN: HighLight("WARN", ConsoleColor.Yellow, ConsoleColor.Black); break; case Logger.LogLevels.DEBUG: HighLight("DEBUG", ConsoleColor.White, ConsoleColor.DarkBlue); break; case Logger.LogLevels.TRACE: HighLight("TRACE", ConsoleColor.Cyan, ConsoleColor.Black); break; default: Console.Write(FormatMessage(timeStamp, lvl, threadName, className, msg)); break; } void HighLight(string pattern, ConsoleColor fontColor, ConsoleColor backgroundColor) { int idx = msg.IndexOf($"] {pattern} "); Console.Write($"{DateTime.Now.ToString("dd-MM HH:mm:ss.fff")} [{threadName}] "); Console.BackgroundColor = backgroundColor; Console.ForegroundColor = fontColor; Console.Write($"{lvl.ToString()}"); Console.BackgroundColor = stdBgColor; Console.ForegroundColor = stdFgColor; Console.Write($" {className} - {msg}{Environment.NewLine}"); } }
protected string FormatMessage(DateTime timeStamp, Logger.LogLevels lvl, string threadName, string className, string msg) => $"{timeStamp.ToString("dd-MM HH:mm:ss.fff")} [{threadName}] {lvl.ToString()} {className} - {msg}{Environment.NewLine}";