From 76ba9c3eb9138d54db758cb0d20d1a08005e988b Mon Sep 17 00:00:00 2001 From: Garry Trinder Date: Fri, 13 Dec 2024 10:01:41 +0000 Subject: [PATCH] Resolve PR comments --- dev-proxy/Logging/ProxyConsoleFormatter.cs | 4 +++- dev-proxy/Logging/ProxyConsoleFormatterOptions.cs | 2 +- dev-proxy/ProxyEngine.cs | 9 +++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dev-proxy/Logging/ProxyConsoleFormatter.cs b/dev-proxy/Logging/ProxyConsoleFormatter.cs index ee00acc..6f790b0 100644 --- a/dev-proxy/Logging/ProxyConsoleFormatter.cs +++ b/dev-proxy/Logging/ProxyConsoleFormatter.cs @@ -48,7 +48,9 @@ private void LogRequest(RequestLog requestLog, string category, IExternalScopePr // don't log intercepted response to console if (messageType == MessageType.InterceptedResponse || - (messageType == MessageType.Skipped && !_options.ShowSkipMessages)) + (messageType == MessageType.Skipped && !_options.ShowSkipMessages) || + (messageType == MessageType.Timestamp && !_options.ShowTimestamps) + ) { return; } diff --git a/dev-proxy/Logging/ProxyConsoleFormatterOptions.cs b/dev-proxy/Logging/ProxyConsoleFormatterOptions.cs index 6b4012a..798a517 100644 --- a/dev-proxy/Logging/ProxyConsoleFormatterOptions.cs +++ b/dev-proxy/Logging/ProxyConsoleFormatterOptions.cs @@ -9,5 +9,5 @@ public class ProxyConsoleFormatterOptions: ConsoleFormatterOptions { public bool ShowSkipMessages { get; set; } = true; - public bool ShowTimestamps { get; set; } = false; + public bool ShowTimestamps { get; set; } = true; } \ No newline at end of file diff --git a/dev-proxy/ProxyEngine.cs b/dev-proxy/ProxyEngine.cs index fcb1e57..f3d01b3 100755 --- a/dev-proxy/ProxyEngine.cs +++ b/dev-proxy/ProxyEngine.cs @@ -475,16 +475,13 @@ async Task OnRequestAsync(object sender, SessionEventArgs e) await e.GetRequestBodyAsString(); } - using var scope = _logger?.BeginScope(e.HttpClient.Request.Method ?? "", e.HttpClient.Request.Url, e.GetHashCode()); + using var scope = _logger.BeginScope(e.HttpClient.Request.Method ?? "", e.HttpClient.Request.Url, e.GetHashCode()); e.UserData = e.HttpClient.Request; - _logger?.LogRequest($"{e.HttpClient.Request.Method} {e.HttpClient.Request.Url}", MessageType.InterceptedRequest, new LoggingContext(e)); + _logger.LogRequest($"{e.HttpClient.Request.Method} {e.HttpClient.Request.Url}", MessageType.InterceptedRequest, new LoggingContext(e)); - if (_config.ShowTimestamps) - { - _logger?.LogRequest($"{DateTimeOffset.UtcNow}", MessageType.Timestamp, new LoggingContext(e)); - } + _logger.LogRequest($"{DateTimeOffset.UtcNow}", MessageType.Timestamp, new LoggingContext(e)); await HandleRequestAsync(e, proxyRequestArgs); }