From cf5c3b8118bc73c0ff07329667021eb221e99f1f Mon Sep 17 00:00:00 2001 From: Gabe Stocco <98900+gfs@users.noreply.github.com> Date: Wed, 19 Oct 2022 14:54:56 -0700 Subject: [PATCH] Fixes encoding for Sarif as well (#411) --- .../Microsoft.DevSkim.CLI/Writers/SarifWriter.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs b/DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs index 4db086be..2b780354 100644 --- a/DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs +++ b/DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/SarifWriter.cs @@ -47,9 +47,16 @@ public override void FlushAndClose() if (OutputPath is string) { - TextWriter.Close(); - File.Delete(OutputPath); - sarifLog.Save(OutputPath); + if (TextWriter is StreamWriter streamWriter) + { + sarifLog.Save(streamWriter); + } + else + { + TextWriter.Close(); + File.Delete(OutputPath); + sarifLog.Save(OutputPath); + } } else {