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 { /// /// The string that this sink currently contains, constructed from the underlying . /// Can be cleared using . /// public string Value { get { lock (this.builder) return this.builder.ToString(); } } /// /// The used to collect logged data from this sink. /// To get its value directly, you can use . /// public StringBuilder StringBuilder { get { lock (this.builder) return this.builder; } } private readonly StringBuilder builder = new StringBuilder(); /// /// 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.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(); } } }