diff --git a/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs b/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs index bbc7099a888502f61797e20e2fb99558e47bc51d..4309c8e34f4a83b9765d8281ea028e11c156cf9b 100644 --- a/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs +++ b/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs @@ -585,7 +585,7 @@ protected virtual void PrintError(Diagnostic diagnostic, TextWriter consoleOutpu consoleOutput.WriteLine(DiagnosticFormatter.Format(diagnostic, Culture)); } - public StreamErrorLogger GetErrorLogger(TextWriter consoleOutput, CancellationToken cancellationToken) + public SarifErrorLogger GetErrorLogger(TextWriter consoleOutput, CancellationToken cancellationToken) { Debug.Assert(Arguments.ErrorLogPath != null); @@ -596,7 +596,7 @@ public StreamErrorLogger GetErrorLogger(TextWriter consoleOutput, CancellationTo FileAccess.Write, FileShare.ReadWrite | FileShare.Delete); - StreamErrorLogger logger; + SarifErrorLogger logger; if (errorLog == null) { Debug.Assert(diagnostics.HasAnyErrors()); @@ -629,7 +629,7 @@ public StreamErrorLogger GetErrorLogger(TextWriter consoleOutput, CancellationTo public virtual int Run(TextWriter consoleOutput, CancellationToken cancellationToken = default(CancellationToken)) { var saveUICulture = CultureInfo.CurrentUICulture; - StreamErrorLogger errorLogger = null; + SarifErrorLogger errorLogger = null; try { diff --git a/src/Compilers/Core/Portable/CommandLine/ErrorLogger.cs b/src/Compilers/Core/Portable/CommandLine/ErrorLogger.cs index 9d0c1d84a3968909ceef34ff527026c848602f07..41ee97d4c2c539f2f0808d5416765cf60075b3dd 100644 --- a/src/Compilers/Core/Portable/CommandLine/ErrorLogger.cs +++ b/src/Compilers/Core/Portable/CommandLine/ErrorLogger.cs @@ -14,27 +14,4 @@ internal abstract class ErrorLogger { public abstract void LogDiagnostic(Diagnostic diagnostic); } - - /// - /// Used for logging all compiler diagnostics into a given . - /// This logger is responsible for closing the given stream on . - /// It is incorrect to use the logger concurrently from multiple threads. - /// - internal abstract class StreamErrorLogger : ErrorLogger, IDisposable - { - protected JsonWriter _writer { get; } // TODO: Rename to Writer. - - public StreamErrorLogger(Stream stream) - { - Debug.Assert(stream != null); - Debug.Assert(stream.Position == 0); - - _writer = new JsonWriter(new StreamWriter(stream)); - } - - public virtual void Dispose() - { - _writer.Dispose(); - } - } } diff --git a/src/Compilers/Core/Portable/CommandLine/SarifErrorLoggerBase.cs b/src/Compilers/Core/Portable/CommandLine/SarifErrorLogger.cs similarity index 88% rename from src/Compilers/Core/Portable/CommandLine/SarifErrorLoggerBase.cs rename to src/Compilers/Core/Portable/CommandLine/SarifErrorLogger.cs index a8eee2ce8256895983741d464321d2a70176b661..2abe1e165bafb2e3df738ea13009951741ec4802 100644 --- a/src/Compilers/Core/Portable/CommandLine/SarifErrorLoggerBase.cs +++ b/src/Compilers/Core/Portable/CommandLine/SarifErrorLogger.cs @@ -4,16 +4,21 @@ using System.Diagnostics; using System.IO; using System.Globalization; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis { - internal abstract class SarifErrorLoggerBase : StreamErrorLogger, IDisposable + internal abstract class SarifErrorLogger : ErrorLogger, IDisposable { + protected JsonWriter _writer { get; } protected readonly CultureInfo _culture; - protected SarifErrorLoggerBase(Stream stream, CultureInfo culture) - : base(stream) + protected SarifErrorLogger(Stream stream, CultureInfo culture) { + Debug.Assert(stream != null); + Debug.Assert(stream.Position == 0); + + _writer = new JsonWriter(new StreamWriter(stream)); _culture = culture; } @@ -22,9 +27,9 @@ protected SarifErrorLoggerBase(Stream stream, CultureInfo culture) protected abstract void WritePhysicalLocation(Location diagnosticLocation); - public override void Dispose() + public virtual void Dispose() { - base.Dispose(); + _writer.Dispose(); } protected void WriteRegion(FileLinePositionSpan span) diff --git a/src/Compilers/Core/Portable/CommandLine/SarifV1ErrorLogger.cs b/src/Compilers/Core/Portable/CommandLine/SarifV1ErrorLogger.cs index cb0f72219075a7c4987708b815edb53cbef1b705..e8d4fc1f58a4f95d44343f3cd68db1a3a9d74cf9 100644 --- a/src/Compilers/Core/Portable/CommandLine/SarifV1ErrorLogger.cs +++ b/src/Compilers/Core/Portable/CommandLine/SarifV1ErrorLogger.cs @@ -22,7 +22,7 @@ namespace Microsoft.CodeAnalysis /// /// To log diagnostics in the standardized SARIF v2.1.0 format, use the SarifV2ErrorLogger. /// - internal sealed class SarifV1ErrorLogger : SarifErrorLoggerBase, IDisposable + internal sealed class SarifV1ErrorLogger : SarifErrorLogger, IDisposable { private readonly DiagnosticDescriptorSet _descriptors; public SarifV1ErrorLogger(Stream stream, string toolName, string toolFileVersion, Version toolAssemblyVersion, CultureInfo culture) diff --git a/src/Compilers/Core/Portable/CommandLine/SarifV2ErrorLogger.cs b/src/Compilers/Core/Portable/CommandLine/SarifV2ErrorLogger.cs index 5283cec0e4d088557fbe69e47874d4853fcead58..5c6a9a2f50b9dd447980d5e0438255b54a3a450e 100644 --- a/src/Compilers/Core/Portable/CommandLine/SarifV2ErrorLogger.cs +++ b/src/Compilers/Core/Portable/CommandLine/SarifV2ErrorLogger.cs @@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis { - internal sealed class SarifV2ErrorLogger : SarifErrorLoggerBase, IDisposable + internal sealed class SarifV2ErrorLogger : SarifErrorLogger, IDisposable { private readonly DiagnosticDescriptorSet _descriptors; diff --git a/src/Scripting/Core/Hosting/CommandLine/CommandLineRunner.cs b/src/Scripting/Core/Hosting/CommandLine/CommandLineRunner.cs index e646e195ffe71ddf99d8225db95c8291d3bf5940..1b9c321daff63511dfe233d3bb11029bc36f0439 100644 --- a/src/Scripting/Core/Hosting/CommandLine/CommandLineRunner.cs +++ b/src/Scripting/Core/Hosting/CommandLine/CommandLineRunner.cs @@ -45,7 +45,7 @@ internal CommandLineRunner(ConsoleIO console, CommonCompiler compiler, ScriptCom /// internal int RunInteractive() { - StreamErrorLogger errorLogger = null; + SarifErrorLogger errorLogger = null; if (_compiler.Arguments.ErrorLogPath != null) { errorLogger = _compiler.GetErrorLogger(_console.Error, CancellationToken.None);