50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System;
|
|
using Swan.Lite.Logging;
|
|
|
|
namespace Swan.Logging {
|
|
/// <summary>
|
|
/// Represents a logger target. This target will write to the
|
|
/// Debug console using System.Diagnostics.Debug.
|
|
/// </summary>
|
|
/// <seealso cref="ILogger" />
|
|
public class DebugLogger : TextLogger, ILogger {
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="DebugLogger"/> class.
|
|
/// </summary>
|
|
protected DebugLogger() {
|
|
// Empty
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the current instance of DebugLogger.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The instance.
|
|
/// </value>
|
|
public static DebugLogger Instance { get; } = new DebugLogger();
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether a debugger is attached.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if this instance is debugger attached; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public static Boolean IsDebuggerAttached => System.Diagnostics.Debugger.IsAttached;
|
|
|
|
/// <inheritdoc/>
|
|
public LogLevel LogLevel { get; set; } = IsDebuggerAttached ? LogLevel.Trace : LogLevel.None;
|
|
|
|
/// <inheritdoc/>
|
|
public void Log(LogMessageReceivedEventArgs logEvent) {
|
|
(String outputMessage, ConsoleColor _) = this.GetOutputAndColor(logEvent);
|
|
|
|
System.Diagnostics.Debug.Write(outputMessage);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void Dispose() {
|
|
// do nothing
|
|
}
|
|
}
|
|
}
|