/// <summary> /// Appends the given message to the logfile, using the specified settings. /// </summary> public override void Log(LogMessage message, LoggerSettings settings) { StringBuilder builder = new StringBuilder(); if (settings.IncludeDate) { builder.Append($"{Date.ToString(settings.DateFormat)} "); } if (settings.IncludeTime) { builder.Append($"{Date.ToString(settings.TimeFormat)} "); } if (settings.IncludeDate || settings.IncludeTime) { builder.Append(' '); } builder.Append(message.Level.ToString().PadRight(7)); if (message.SenderType != null) { builder.Append($"{FormatTypeName(message.SenderType)}: "); } int left = builder.Length; builder.Append(message.Message); if (!string.IsNullOrEmpty(message.AdditionalInfo)) { foreach (string line in message.AdditionalInfo.Split('\n')) { builder.AppendLine(); builder.Append(' ', left); builder.Append(line); } } _streamWriter.WriteLine(builder.ToString()); }
/// <summary> /// Logs the specified message to the console, using the given logger settings. /// </summary> public override void Log(LogMessage message, LoggerSettings settings) { if (settings.IncludeDate) { Console.Write($"{Date.ToString(settings.DateFormat)} "); } if (settings.IncludeTime) { Console.Write($"{Date.ToString(settings.TimeFormat)} "); } if (settings.IncludeDate || settings.IncludeTime) { Console.Write(' '); } WriteLogLevel(message.Level); Console.Write(" "); if (message.SenderType != null) { Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write($"{FormatTypeName(message.SenderType)}: "); Console.ResetColor(); } int left = Console.CursorLeft; Console.WriteLine(message.Message); if (!string.IsNullOrEmpty(message.AdditionalInfo)) { foreach (string line in message.AdditionalInfo.Split('\n')) { Console.CursorLeft = left; Console.WriteLine(line); } } }
/// <summary> /// Logs the specified message, using the specified settings. /// </summary> public abstract void Log(LogMessage message, LoggerSettings settings);