From c35dcb2b949096d257c743672ce7f2fd276828ad Mon Sep 17 00:00:00 2001 From: nietras Date: Sat, 19 Aug 2023 01:24:57 +0200 Subject: [PATCH] Refactor out base TextLogger from StreamLogger (#2406) * Refactor out base TextWriterLogger from StreamLogger * rename to TextLogger * fix Id * rearrange --- src/BenchmarkDotNet/Loggers/StreamLogger.cs | 25 ++++++--------------- src/BenchmarkDotNet/Loggers/TextLogger.cs | 25 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 src/BenchmarkDotNet/Loggers/TextLogger.cs diff --git a/src/BenchmarkDotNet/Loggers/StreamLogger.cs b/src/BenchmarkDotNet/Loggers/StreamLogger.cs index d9c9bc2b10..7e7730de5f 100644 --- a/src/BenchmarkDotNet/Loggers/StreamLogger.cs +++ b/src/BenchmarkDotNet/Loggers/StreamLogger.cs @@ -1,28 +1,17 @@ -using System; -using System.IO; +using System.IO; using JetBrains.Annotations; namespace BenchmarkDotNet.Loggers { - public class StreamLogger : ILogger, IDisposable + public class StreamLogger : TextLogger { - private readonly StreamWriter writer; - - public StreamLogger(StreamWriter writer) => this.writer = writer; - - public void Dispose() => writer.Dispose(); + public StreamLogger(StreamWriter writer) : base(writer) { } [PublicAPI] - public StreamLogger(string filePath, bool append = false) => writer = new StreamWriter(filePath, append); - - public string Id => nameof(StreamLogger); - public int Priority => 0; - public void Write(LogKind logKind, string text) => writer.Write(text); - - public void WriteLine() => writer.WriteLine(); - - public void WriteLine(LogKind logKind, string text) => writer.WriteLine(text); + public StreamLogger(string filePath, bool append = false) + : this(new StreamWriter(filePath, append)) + { } - public void Flush() => writer.Flush(); + public override string Id => nameof(StreamLogger); } } diff --git a/src/BenchmarkDotNet/Loggers/TextLogger.cs b/src/BenchmarkDotNet/Loggers/TextLogger.cs new file mode 100644 index 0000000000..e261f07f26 --- /dev/null +++ b/src/BenchmarkDotNet/Loggers/TextLogger.cs @@ -0,0 +1,25 @@ +using System; +using System.IO; + +namespace BenchmarkDotNet.Loggers +{ + public class TextLogger : ILogger, IDisposable + { + private readonly TextWriter writer; + + public TextLogger(TextWriter writer) => this.writer = writer; + + public virtual string Id => nameof(TextLogger); + public int Priority => 0; + + public void Write(LogKind logKind, string text) => writer.Write(text); + + public void WriteLine() => writer.WriteLine(); + + public void WriteLine(LogKind logKind, string text) => writer.WriteLine(text); + + public void Flush() => writer.Flush(); + + public void Dispose() => writer.Dispose(); + } +}