From 9831d28790ac8edb302c38302600b70ddeb9270c Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 28 Sep 2020 13:53:55 +0200 Subject: [PATCH 1/2] always log error responses with error level --- src/OmniSharp.Stdio/Host.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/OmniSharp.Stdio/Host.cs b/src/OmniSharp.Stdio/Host.cs index 4cc441794f..017f7ff44b 100644 --- a/src/OmniSharp.Stdio/Host.cs +++ b/src/OmniSharp.Stdio/Host.cs @@ -232,9 +232,9 @@ private async Task HandleRequest(string json, ILogger logger) } finally { - if (logger.IsEnabled(LogLevel.Debug)) + if (logger.IsEnabled(LogLevel.Debug) || !response.Success) { - LogResponse(response.ToString(), logger); + LogResponse(response.ToString(), logger, response.Success); } // actually write it @@ -257,14 +257,22 @@ void LogRequest(string json, ILogger logger) } } - void LogResponse(string json, ILogger logger) + void LogResponse(string json, ILogger logger, bool isSuccess) { var builder = _cachedStringBuilder.Acquire(); try { builder.AppendLine("************ Response ************ "); builder.Append(JToken.Parse(json).ToString(Formatting.Indented)); - logger.LogDebug(builder.ToString()); + + if (isSuccess) + { + logger.LogDebug(builder.ToString()); + } + else + { + logger.LogError(builder.ToString()); + } } finally { From c129cb46b74f330d412d392206629c5fffac8dde Mon Sep 17 00:00:00 2001 From: filipw Date: Mon, 28 Sep 2020 13:58:58 +0200 Subject: [PATCH 2/2] added a helpful comment --- src/OmniSharp.Stdio/Host.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/OmniSharp.Stdio/Host.cs b/src/OmniSharp.Stdio/Host.cs index 017f7ff44b..97cb8d057e 100644 --- a/src/OmniSharp.Stdio/Host.cs +++ b/src/OmniSharp.Stdio/Host.cs @@ -232,6 +232,8 @@ private async Task HandleRequest(string json, ILogger logger) } finally { + // response gets logged when Debug or more detailed log level is enabled + // or when we have unsuccessful response (exception) if (logger.IsEnabled(LogLevel.Debug) || !response.Success) { LogResponse(response.ToString(), logger, response.Success);