using System;
using System.Text;
namespace ExtremelySimpleLogger {
///
/// A sink is a way for log messages passed to a to be processed in a certain way.
///
public abstract class Sink : IDisposable {
///
/// The minimum level that a log message needs to have for it to be processed by this sink.
///
public LogLevel MinimumLevel { get; set; } = LogLevel.Trace;
///
/// The with which log messages should be formatted.
/// is used if this is .
///
public LogFormatter Formatter { get; set; }
///
/// If this property is set to false
, this sink will not log any messages.
///
public bool IsEnabled { get; set; } = true;
///
/// Logs a message in the way specified by the sink's implementation.
///
/// The logger that the message was passed to
/// The importance level of this message
/// The message
/// An optional exception whose stack trace will be appended to the message
public virtual void Log(Logger logger, LogLevel level, object message, Exception e = null) {
var formatter = this.Formatter ?? logger.DefaultFormatter;
this.Log(logger, level, formatter.Invoke(logger, level, message, e));
}
///
/// Logs the given message, which has already been formatted using or .
///
/// The logger that the message was passed to
/// The importance level of this message
/// The message to log
protected abstract void Log(Logger logger, LogLevel level, string s);
///
/// Disposes this sink, freeing all of the resources it uses.
///
public virtual void Dispose() {}
}
}