Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass in the request when no matching is found to the warn logger #1182

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

JasonLandbridge
Copy link
Contributor

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

@JasonLandbridge JasonLandbridge marked this pull request as ready for review September 27, 2024 16:08
@StefH StefH added the feature label Sep 27, 2024
@StefH StefH merged commit 9599442 into WireMock-Net:master Sep 27, 2024
8 checks passed
@JasonLandbridge JasonLandbridge deleted the patch-1 branch September 27, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants