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 { get { lock (this.builder) return this.builder.ToString(); } } /// /// Logs the given message, which has already been formatted using . /// /// 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.builder) this.builder.AppendLine(s); } /// /// Clears the string that this sink currently contains. /// After this call, will be empty. /// public void Clear() { lock (this.builder) this.builder.Clear(); } } }