using System.IO;
namespace ExtremelySimpleLogger {
///
/// A that writes log output to an underlying .
/// Note that is a variation of this sink that additionally includes console colors.
///
public class WriterSink : Sink {
private readonly TextWriter writer;
private readonly bool autoClose;
///
/// Creates a new writer sink with the given settings.
///
/// The writer to write to.
/// Whether the underlying should be closed automatically when this sink is disposed in .
public WriterSink(TextWriter writer, bool autoClose = false) {
this.writer = writer;
this.autoClose = autoClose;
}
///
/// 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 override void Log(Logger logger, LogLevel level, string s) {
lock (this.writer)
this.writer.WriteLine(s);
}
///
public override void Dispose() {
if (this.autoClose) {
lock (this.writer)
this.writer.Dispose();
}
}
}
}