StreamLogger is for some reason (other than name) tied to only being useable with StreamWriter, which is just a TextWriter, as far as I can tell there is no reason for the implementation to tie into it being a StreamWriter and one could easily refactor to TextWriter or extracting a base class TextWriterLogger with all code, but which allows using a TextWriter instead. This would allow exporting to in-memory StringWriter instead of having to go through a MemoryStream.
|
public class StreamLogger : ILogger, IDisposable |
|
{ |
|
private readonly StreamWriter writer; |
|
|
|
public StreamLogger(StreamWriter writer) => this.writer = writer; |
|
|
|
public void Dispose() => writer.Dispose(); |
|
|
|
[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 void Flush() => writer.Flush(); |
|
} |
|
} |
StreamLogger is for some reason (other than name) tied to only being useable with
StreamWriter, which is just aTextWriter, as far as I can tell there is no reason for the implementation to tie into it being aStreamWriterand one could easily refactor toTextWriteror extracting a base classTextWriterLoggerwith all code, but which allows using aTextWriterinstead. This would allow exporting to in-memoryStringWriterinstead of having to go through aMemoryStream.BenchmarkDotNet/src/BenchmarkDotNet/Loggers/StreamLogger.cs
Lines 7 to 28 in d058c7b