diff --git a/ExtremelySimpleLogger/ConsoleSink.cs b/ExtremelySimpleLogger/ConsoleSink.cs
index c3f4e33..8abe01e 100644
--- a/ExtremelySimpleLogger/ConsoleSink.cs
+++ b/ExtremelySimpleLogger/ConsoleSink.cs
@@ -5,6 +5,7 @@ using System.IO;
namespace ExtremelySimpleLogger {
///
/// A that writes log output to or .
+ /// This class is a variation of the .
///
public class ConsoleSink : Sink {
@@ -17,7 +18,6 @@ namespace ExtremelySimpleLogger {
{LogLevel.Error, ConsoleColor.DarkRed},
{LogLevel.Fatal, ConsoleColor.DarkRed}
};
- private readonly object locker = new object();
private readonly TextWriter console;
///
@@ -63,7 +63,7 @@ namespace ExtremelySimpleLogger {
/// The importance level of this message
/// The message to log
protected override void Log(Logger logger, LogLevel level, string s) {
- lock (this.locker) {
+ lock (this.console) {
var color = this.GetColor(level);
if (color.HasValue)
Console.ForegroundColor = color.Value;
diff --git a/ExtremelySimpleLogger/WriterSink.cs b/ExtremelySimpleLogger/WriterSink.cs
new file mode 100644
index 0000000..9f3b5ee
--- /dev/null
+++ b/ExtremelySimpleLogger/WriterSink.cs
@@ -0,0 +1,43 @@
+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();
+ }
+ }
+
+ }
+}