From eb7cf46c95a5b7e6744c7c9f5642878c5e49e1f7 Mon Sep 17 00:00:00 2001 From: JvE-iO Date: Wed, 29 Jan 2025 12:54:46 +0100 Subject: [PATCH 1/3] Add exception message to logging when mapping fails due to an exception. --- src/WireMock.Net/Owin/WireMockMiddleware.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WireMock.Net/Owin/WireMockMiddleware.cs b/src/WireMock.Net/Owin/WireMockMiddleware.cs index a5445344a..6ccd32424 100644 --- a/src/WireMock.Net/Owin/WireMockMiddleware.cs +++ b/src/WireMock.Net/Owin/WireMockMiddleware.cs @@ -224,7 +224,7 @@ private async Task InvokeInternalAsync(IContext ctx) } catch (Exception ex) { - _options.Logger.Error("HttpStatusCode set to 404 : No matching mapping found", ex); + _options.Logger.Error("HttpStatusCode set to 404 : 'No matching mapping found', due to exception '{0}'", ex); var notFoundResponse = ResponseMessageBuilder.Create(HttpStatusCode.NotFound, WireMockConstants.NoMatchingFound); await _responseMapper.MapAsync(notFoundResponse, ctx.Response).ConfigureAwait(false); From 4951ef36dcfe5ca676a462ee68ff31e68a1c2b18 Mon Sep 17 00:00:00 2001 From: Joris van Eijden Date: Thu, 30 Jan 2025 08:42:17 +0100 Subject: [PATCH 2/3] Revert "Add exception message to logging when mapping fails due to an exception." This reverts commit eb7cf46c95a5b7e6744c7c9f5642878c5e49e1f7. --- src/WireMock.Net/Owin/WireMockMiddleware.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WireMock.Net/Owin/WireMockMiddleware.cs b/src/WireMock.Net/Owin/WireMockMiddleware.cs index 6ccd32424..a5445344a 100644 --- a/src/WireMock.Net/Owin/WireMockMiddleware.cs +++ b/src/WireMock.Net/Owin/WireMockMiddleware.cs @@ -224,7 +224,7 @@ private async Task InvokeInternalAsync(IContext ctx) } catch (Exception ex) { - _options.Logger.Error("HttpStatusCode set to 404 : 'No matching mapping found', due to exception '{0}'", ex); + _options.Logger.Error("HttpStatusCode set to 404 : No matching mapping found", ex); var notFoundResponse = ResponseMessageBuilder.Create(HttpStatusCode.NotFound, WireMockConstants.NoMatchingFound); await _responseMapper.MapAsync(notFoundResponse, ctx.Response).ConfigureAwait(false); From 2e247ff2eabfc5d90ac24c309eeb5068ab13e378 Mon Sep 17 00:00:00 2001 From: Joris van Eijden Date: Thu, 30 Jan 2025 08:44:29 +0100 Subject: [PATCH 3/3] Fix loggers with improved exception logging. --- .../WireMock.Net.WebApplication.NET6/WireMockService.cs | 4 ++-- src/WireMock.Net.TUnit/TUnitWireMockLogger.cs | 4 ++-- src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/WireMock.Net.WebApplication.NET6/WireMockService.cs b/examples/WireMock.Net.WebApplication.NET6/WireMockService.cs index 58bbdc14b..d35f9c970 100644 --- a/examples/WireMock.Net.WebApplication.NET6/WireMockService.cs +++ b/examples/WireMock.Net.WebApplication.NET6/WireMockService.cs @@ -52,9 +52,9 @@ public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminreques _logger.LogDebug("Admin[{0}] {1}", isAdminrequest, message); } - public void Error(string formatString, Exception exception) + public void Error(string message, Exception exception) { - _logger.LogError(formatString, exception.Message); + _logger.LogError(exception, message); } } diff --git a/src/WireMock.Net.TUnit/TUnitWireMockLogger.cs b/src/WireMock.Net.TUnit/TUnitWireMockLogger.cs index a38926004..050c84ec0 100644 --- a/src/WireMock.Net.TUnit/TUnitWireMockLogger.cs +++ b/src/WireMock.Net.TUnit/TUnitWireMockLogger.cs @@ -51,9 +51,9 @@ public void Error(string formatString, params object[] args) } /// - public void Error(string formatString, Exception exception) + public void Error(string message, Exception exception) { - _tUnitLogger.LogError(Format("Error", formatString, exception.Message), exception); + _tUnitLogger.LogError(Format("Error", $"{message} {{0}}", exception)); if (exception is AggregateException ae) { diff --git a/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs b/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs index df83bac37..0f0cbed2a 100644 --- a/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs +++ b/src/WireMock.Net.xUnit/TestOutputHelperWireMockLogger.cs @@ -50,15 +50,15 @@ public void Error(string formatString, params object[] args) } /// - public void Error(string formatString, Exception exception) + public void Error(string message, Exception exception) { - _testOutputHelper.WriteLine(Format("Error", formatString, exception.Message)); + _testOutputHelper.WriteLine(Format("Error", $"{message} {{0}}", exception)); if (exception is AggregateException ae) { ae.Handle(ex => { - _testOutputHelper.WriteLine(Format("Error", "Exception {0}", ex.Message)); + _testOutputHelper.WriteLine(Format("Error", "Exception {0}", ex)); return true; }); }