using System;
using Swan.Lite.Logging;
namespace Swan.Logging
{
///
/// Represents a Console implementation of ILogger.
///
///
public class ConsoleLogger : TextLogger, ILogger
{
///
/// Initializes a new instance of the class.
///
protected ConsoleLogger()
{
// Empty
}
///
/// Gets the current instance of ConsoleLogger.
///
///
/// The instance.
///
public static ConsoleLogger Instance { get; } = new ConsoleLogger();
///
/// Gets or sets the debug logging prefix.
///
///
/// The debug prefix.
///
public static string DebugPrefix { get; set; } = "DBG";
///
/// Gets or sets the trace logging prefix.
///
///
/// The trace prefix.
///
public static string TracePrefix { get; set; } = "TRC";
///
/// Gets or sets the warning logging prefix.
///
///
/// The warn prefix.
///
public static string WarnPrefix { get; set; } = "WRN";
///
/// Gets or sets the fatal logging prefix.
///
///
/// The fatal prefix.
///
public static string FatalPrefix { get; set; } = "FAT";
///
/// Gets or sets the error logging prefix.
///
///
/// The error prefix.
///
public static string ErrorPrefix { get; set; } = "ERR";
///
/// Gets or sets the information logging prefix.
///
///
/// The information prefix.
///
public static string InfoPrefix { get; set; } = "INF";
///
/// Gets or sets the color of the information output logging.
///
///
/// The color of the information.
///
public static ConsoleColor InfoColor { get; set; } = ConsoleColor.Cyan;
///
/// Gets or sets the color of the debug output logging.
///
///
/// The color of the debug.
///
public static ConsoleColor DebugColor { get; set; } = ConsoleColor.Gray;
///
/// Gets or sets the color of the trace output logging.
///
///
/// The color of the trace.
///
public static ConsoleColor TraceColor { get; set; } = ConsoleColor.DarkGray;
///
/// Gets or sets the color of the warning logging.
///
///
/// The color of the warn.
///
public static ConsoleColor WarnColor { get; set; } = ConsoleColor.Yellow;
///
/// Gets or sets the color of the error logging.
///
///
/// The color of the error.
///
public static ConsoleColor ErrorColor { get; set; } = ConsoleColor.DarkRed;
///
/// Gets or sets the color of the error logging.
///
///
/// The color of the error.
///
public static ConsoleColor FatalColor { get; set; } = ConsoleColor.Red;
///
public LogLevel LogLevel { get; set; } = DebugLogger.IsDebuggerAttached ? LogLevel.Trace : LogLevel.Info;
///
public void Log(LogMessageReceivedEventArgs logEvent)
{
// Select the writer based on the message type
var writer = logEvent.MessageType == LogLevel.Error
? TerminalWriters.StandardError
: TerminalWriters.StandardOutput;
var (outputMessage, color) = GetOutputAndColor(logEvent);
Terminal.Write(outputMessage, color, writer);
}
///
public void Dispose()
{
// Do nothing
}
}
}