diff --git a/ExtremelySimpleLogger/Logger.cs b/ExtremelySimpleLogger/Logger.cs index d93e8b1..a17a707 100644 --- a/ExtremelySimpleLogger/Logger.cs +++ b/ExtremelySimpleLogger/Logger.cs @@ -6,13 +6,13 @@ namespace ExtremelySimpleLogger { /// The implementation of a logger, which is a wrapper class around multiple logging . /// /// To start logging with a logger, its need to be initialized. - /// There are two default implementations: and . + /// There are two default implementations: , and . /// public class Logger { /// /// All of the instances that this logger logs to. - /// By default, and are available. + /// By default, , and are available. /// public List Sinks { get; set; } = new List(); /// diff --git a/ExtremelySimpleLogger/StringSink.cs b/ExtremelySimpleLogger/StringSink.cs new file mode 100644 index 0000000..70fad4b --- /dev/null +++ b/ExtremelySimpleLogger/StringSink.cs @@ -0,0 +1,34 @@ +using System.Text; + +namespace ExtremelySimpleLogger { + /// + /// A that writes output to a string, which can be queried using . + /// Note that this uses a internally for performance. + /// + public class StringSink : Sink { + + private readonly StringBuilder builder = new StringBuilder(); + /// + /// The string that this sink currently contains. + /// Can be cleared using . + /// + public string Value => this.builder.ToString(); + + /// + /// Logs the given message, which has already been formatted using . + /// + /// The message to log + public override void Log(string s) { + this.builder.AppendLine(s); + } + + /// + /// Clears the string that this sink currently contains. + /// After this call, will be empty. + /// + public void Clear() { + this.builder.Clear(); + } + + } +} \ No newline at end of file diff --git a/README.md b/README.md index 42b559f..e2314c3 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ var logger = new Logger { Since there are multiple ways for logging data to be processed, the logger needs to receive a set of `Sink` instances. By default, the following sinks are available: - `FileSink`, which outputs logging data to a file - `ConsoleSink`, which outputs logging data to the default console +- `StringSink`, which stores logging data in a string There are multiple ways to easily log messages with your newly created logger: ```cs