[PR #1182] [MERGED] pass in the request when no matching is found to the warn logger #1272

Closed
opened 2025-12-29 09:19:07 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/wiremock/WireMock.Net/pull/1182
Author: @JasonLandbridge
Created: 9/27/2024
Status: Merged
Merged: 9/27/2024
Merged by: @StefH

Base: masterHead: patch-1


📝 Commits (1)

  • ef7caf0 pass in the request when no matching is found to the warn logger

📊 Changes

1 file changed (+2 additions, -2 deletions)

View changed files

📝 src/WireMock.Net/Owin/WireMockMiddleware.cs (+2 -2)

📄 Description

Hi there,

Coming back to this issue: #1086

I wound a way to regain the functionality by creating a custom logger and then throw exceptions once it matches. So:

WireMockServer.Start(
            new WireMockServerSettings()
            {
                Logger = new WiremockLogger(_log),
                HostingScheme = HostingScheme.HttpAndHttps,
            }
        );


public class WiremockLogger : IWireMockLogger
{
    private readonly ILog _log;

    public WiremockLogger(ILog log)
    {
        _log = log;
    }

    public void Debug(string formatString, params object[] args)
    {
        _log.Debug(formatString, args);
    }

    public void Info(string formatString, params object[] args)
    {
        _log.Information(formatString, args);
    }

    public void Warn(string formatString, params object[] args)
    {
        _log.Warning(formatString, args);
        if (formatString.Contains("No matching mapping found"))
            throw new Exception(formatString);
    }

    public void Error(string formatString, params object[] args)
    {
        _log.Error(formatString, args);
        throw new Exception(formatString);
    }

    public void Error(string formatString, Exception exception)
    {
        _log.Error(exception);
        throw exception;
    }

    public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
    {
        _log.DebugLine(logEntryModel.ToString());
    }
}

This works, however it would be great if I also get the request object to see which url I have not mapped yet and or has changed from a previous match. This is why I pass in the request into the warn log


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/wiremock/WireMock.Net/pull/1182 **Author:** [@JasonLandbridge](https://github.com/JasonLandbridge) **Created:** 9/27/2024 **Status:** ✅ Merged **Merged:** 9/27/2024 **Merged by:** [@StefH](https://github.com/StefH) **Base:** `master` ← **Head:** `patch-1` --- ### 📝 Commits (1) - [`ef7caf0`](https://github.com/wiremock/WireMock.Net/commit/ef7caf07256198c654d14468ef1c1762f3c3b818) pass in the request when no matching is found to the warn logger ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/WireMock.Net/Owin/WireMockMiddleware.cs` (+2 -2) </details> ### 📄 Description Hi there, Coming back to this issue: #1086 I wound a way to regain the functionality by creating a custom logger and then throw exceptions once it matches. So: ```csharp WireMockServer.Start( new WireMockServerSettings() { Logger = new WiremockLogger(_log), HostingScheme = HostingScheme.HttpAndHttps, } ); ``` ```csharp public class WiremockLogger : IWireMockLogger { private readonly ILog _log; public WiremockLogger(ILog log) { _log = log; } public void Debug(string formatString, params object[] args) { _log.Debug(formatString, args); } public void Info(string formatString, params object[] args) { _log.Information(formatString, args); } public void Warn(string formatString, params object[] args) { _log.Warning(formatString, args); if (formatString.Contains("No matching mapping found")) throw new Exception(formatString); } public void Error(string formatString, params object[] args) { _log.Error(formatString, args); throw new Exception(formatString); } public void Error(string formatString, Exception exception) { _log.Error(exception); throw exception; } public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest) { _log.DebugLine(logEntryModel.ToString()); } } ``` This works, however it would be great if I also get the request object to see which url I have not mapped yet and or has changed from a previous match. This is why I pass in the request into the warn log --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 09:19:07 +01:00
adam closed this issue 2025-12-29 09:19:07 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#1272