Skip to content

How to log un/matched requests and responses? #1396

@Swimburger

Description

@Swimburger

This library is super useful, but it's been hard to debug because requests and responses are not being logged.
Ideally, we'd like to not log by default, but log when debugging is enabled somehow. This is our current setup:

BaseMockServerTest.cs:

using NUnit.Framework;
using SeedExhaustive;
using WireMock.Admin.Requests;
using WireMock.Logging;
using WireMock.Server;
using WireMock.Settings;

namespace SeedExhaustive.Test.Unit.MockServer;

[SetUpFixture]
public class BaseMockServerTest
{
    protected static WireMockServer Server { get; set; } = null!;

    protected static SeedExhaustiveClient Client { get; set; } = null!;

    protected static RequestOptions RequestOptions { get; set; } = new();

    [OneTimeSetUp]
    public void GlobalSetup()
    {
        // Start the WireMock server
        Server = WireMockServer.Start(
            new WireMockServerSettings { 
                Logger = new WireMockConsoleLogger(),
                SaveUnmatchedRequests = true,
                MaxRequestLogCount = 100,
                RequestLogExpirationDuration = 6,
            }
        );

        // Initialize the Client
        Client = new SeedExhaustiveClient(
            "TOKEN",
            clientOptions: new ClientOptions { BaseUrl = Server.Urls[0], MaxRetries = 0 }
        );
    }

    [OneTimeTearDown]
    public void GlobalTeardown()
    {
        Server.Stop();
        Server.Dispose();
    }
}

GetAndReturnListOfObjectsTest.cs:

using NUnit.Framework;
using SeedExhaustive.Core;
using SeedExhaustive.Test.Unit.MockServer;
using SeedExhaustive.Types.Object;

namespace SeedExhaustive.Test.Unit.MockServer.Endpoints.Container;

[TestFixture]
public class GetAndReturnListOfObjectsTest : BaseMockServerTest
{
    [NUnit.Framework.Test]
    public async Task MockServerTest()
    {
        const string requestJson = """
            [
              {
                "string": "string"
              },
              {
                "string": "string"
              }
            ]
            """;

        const string mockResponse = """
            [
              {
                "string": "string"
              },
              {
                "string": "string"
              }
            ]
            """;

        Server
            .Given(
                WireMock
                    .RequestBuilders.Request.Create()
                    .WithPath("/container/list-of-objects")
                    .UsingPost()
                    .WithBodyAsJson(requestJson)
            )
            .RespondWith(
                WireMock
                    .ResponseBuilders.Response.Create()
                    .WithStatusCode(200)
                    .WithBody(mockResponse)
            );

        var response = await Client.Endpoints.Container.GetAndReturnListOfObjectsAsync(
            new List<ObjectWithRequiredField>()
            {
                new ObjectWithRequiredField { String = "string" },
                new ObjectWithRequiredField { String = "string" },
            }
        );
        Assert.That(
            response,
            Is.EqualTo(JsonUtils.Deserialize<IEnumerable<ObjectWithRequiredField>>(mockResponse))
                .UsingDefaults()
        );
    }
}

We use version 1.7.4 but 1.19.0 also doens't log. We do see the server configation logged:

SeedExhaustive.Test.Unit.MockServer.Endpoints.Container.GetAndReturnListOfObjectsTest

[MockServer Info] By Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net)
12/17/2025 11:35:35 PM [Info] : By Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net)
[MockServer Debug] Server settings {
  "Port": null,
  "UseSSL": null,
  "HostingScheme": null,
  "UseHttp2": null,
  "StartAdminInterface": null,
  "ReadStaticMappings": null,
  "WatchStaticMappings": null,
  "WatchStaticMappingsInSubdirectories": null,
  "ProxyAndRecordSettings": null,
  "Urls": null,
  "StartTimeout": 10000,
  "AllowPartialMapping": null,
  "AdminUsername": null,
  "AdminPassword": null,
  "AdminAzureADTenant": null,
  "AdminAzureADAudience": null,
  "RequestLogExpirationDuration": null,
  "MaxRequestLogCount": null,
  "CorsPolicyOptions": null,
  "AllowCSharpCodeMatcher": null,
  "AllowBodyForAllHttpMethods": null,
  "AllowOnlyDefinedHttpStatusCodeInResponse": null,
  "DisableJsonBodyParsing": null,
  "DisableRequestBodyDecompressing": null,
  "DisableDeserializeFormUrlEncoded": null,
  "HandleRequestsSynchronously": null,
  "CertificateSettings": null,
  "CustomCertificateDefined": false,
  "ClientCertificateMode": 0,
  "AcceptAnyClientCertificate": false,
  "WebhookSettings": null,
  "UseRegexExtended": true,
  "SaveUnmatchedRequests": null,
  "DoNotSaveDynamicResponseInLogEntry": null,
  "QueryParameterMultipleValueSupport": null,
  "ProtoDefinitions": null,
  "GraphQLSchemas": null,
  "AdminPath": null
}
12/17/2025 11:35:35 PM [Debug] : Server settings {
  "Port": null,
  "UseSSL": null,
  "HostingScheme": null,
  "UseHttp2": null,
  "StartAdminInterface": null,
  "ReadStaticMappings": null,
  "WatchStaticMappings": null,
  "WatchStaticMappingsInSubdirectories": null,
  "ProxyAndRecordSettings": null,
  "Urls": null,
  "StartTimeout": 10000,
  "AllowPartialMapping": null,
  "AdminUsername": null,
  "AdminPassword": null,
  "AdminAzureADTenant": null,
  "AdminAzureADAudience": null,
  "RequestLogExpirationDuration": null,
  "MaxRequestLogCount": null,
  "CorsPolicyOptions": null,
  "AllowCSharpCodeMatcher": null,
  "AllowBodyForAllHttpMethods": null,
  "AllowOnlyDefinedHttpStatusCodeInResponse": null,
  "DisableJsonBodyParsing": null,
  "DisableRequestBodyDecompressing": null,
  "DisableDeserializeFormUrlEncoded": null,
  "HandleRequestsSynchronously": null,
  "CertificateSettings": null,
  "CustomCertificateDefined": false,
  "ClientCertificateMode": 0,
  "AcceptAnyClientCertificate": false,
  "WebhookSettings": null,
  "UseRegexExtended": true,
  "SaveUnmatchedRequests": null,
  "DoNotSaveDynamicResponseInLogEntry": null,
  "QueryParameterMultipleValueSupport": null,
  "ProtoDefinitions": null,
  "GraphQLSchemas": null,
  "AdminPath": null
}
[MockServer Info] Server using .NET 8.0
12/17/2025 11:35:35 PM [Info] : Server using .NET 8.0
12/17/2025 11:47:34 PM [Info] : By Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net)
12/17/2025 11:47:34 PM [Debug] : Server settings {
  "Port": null,
  "UseSSL": null,
  "HostingScheme": null,
  "UseHttp2": null,
  "StartAdminInterface": null,
  "ReadStaticMappings": null,
  "WatchStaticMappings": null,
  "WatchStaticMappingsInSubdirectories": null,
  "ProxyAndRecordSettings": null,
  "Urls": null,
  "StartTimeout": 10000,
  "AllowPartialMapping": null,
  "AdminUsername": null,
  "AdminPassword": null,
  "AdminAzureADTenant": null,
  "AdminAzureADAudience": null,
  "RequestLogExpirationDuration": null,
  "MaxRequestLogCount": null,
  "CorsPolicyOptions": null,
  "AllowCSharpCodeMatcher": null,
  "AllowBodyForAllHttpMethods": null,
  "AllowOnlyDefinedHttpStatusCodeInResponse": null,
  "DisableJsonBodyParsing": null,
  "DisableRequestBodyDecompressing": null,
  "DisableDeserializeFormUrlEncoded": null,
  "HandleRequestsSynchronously": null,
  "CertificateSettings": null,
  "CustomCertificateDefined": false,
  "ClientCertificateMode": 0,
  "AcceptAnyClientCertificate": false,
  "WebhookSettings": null,
  "UseRegexExtended": true,
  "SaveUnmatchedRequests": null,
  "DoNotSaveDynamicResponseInLogEntry": null,
  "QueryParameterMultipleValueSupport": null,
  "ProtoDefinitions": null,
  "GraphQLSchemas": null,
  "AdminPath": null
}
12/17/2025 11:47:34 PM [Info] : Server using .NET 8.0
12/17/2025 11:49:30 PM [Info] : By Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net)
12/17/2025 11:49:30 PM [Debug] : Server settings {
  "Port": null,
  "UseSSL": null,
  "HostingScheme": null,
  "UseHttp2": null,
  "StartAdminInterface": null,
  "ReadStaticMappings": null,
  "WatchStaticMappings": null,
  "WatchStaticMappingsInSubdirectories": null,
  "ProxyAndRecordSettings": null,
  "Urls": null,
  "StartTimeout": 10000,
  "AllowPartialMapping": null,
  "AdminUsername": null,
  "AdminPassword": null,
  "AdminAzureADTenant": null,
  "AdminAzureADAudience": null,
  "RequestLogExpirationDuration": null,
  "MaxRequestLogCount": null,
  "CorsPolicyOptions": null,
  "AllowCSharpCodeMatcher": null,
  "AllowBodyForAllHttpMethods": null,
  "AllowOnlyDefinedHttpStatusCodeInResponse": null,
  "DisableJsonBodyParsing": null,
  "DisableRequestBodyDecompressing": null,
  "DisableDeserializeFormUrlEncoded": null,
  "HandleRequestsSynchronously": null,
  "CertificateSettings": null,
  "CustomCertificateDefined": false,
  "ClientCertificateMode": 0,
  "AcceptAnyClientCertificate": false,
  "WebhookSettings": null,
  "UseRegexExtended": true,
  "SaveUnmatchedRequests": true,
  "DoNotSaveDynamicResponseInLogEntry": null,
  "QueryParameterMultipleValueSupport": null,
  "ProtoDefinitions": null,
  "GraphQLSchemas": null,
  "AdminPath": null
}
12/17/2025 11:49:30 PM [Info] : Server using .NET 8.0
12/17/2025 11:51:44 PM [Info] : By Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net)
12/17/2025 11:51:44 PM [Debug] : Server settings {
  "Port": null,
  "UseSSL": null,
  "HostingScheme": null,
  "UseHttp2": null,
  "StartAdminInterface": null,
  "ReadStaticMappings": null,
  "WatchStaticMappings": null,
  "WatchStaticMappingsInSubdirectories": null,
  "ProxyAndRecordSettings": null,
  "Urls": null,
  "StartTimeout": 10000,
  "AllowPartialMapping": null,
  "AdminUsername": null,
  "AdminPassword": null,
  "AdminAzureADTenant": null,
  "AdminAzureADAudience": null,
  "RequestLogExpirationDuration": 6,
  "MaxRequestLogCount": 100,
  "CorsPolicyOptions": null,
  "AllowCSharpCodeMatcher": null,
  "AllowBodyForAllHttpMethods": null,
  "AllowOnlyDefinedHttpStatusCodeInResponse": null,
  "DisableJsonBodyParsing": null,
  "DisableRequestBodyDecompressing": null,
  "DisableDeserializeFormUrlEncoded": null,
  "HandleRequestsSynchronously": null,
  "CertificateSettings": null,
  "CustomCertificateDefined": false,
  "ClientCertificateMode": 0,
  "AcceptAnyClientCertificate": false,
  "WebhookSettings": null,
  "UseRegexExtended": true,
  "SaveUnmatchedRequests": true,
  "DoNotSaveDynamicResponseInLogEntry": null,
  "QueryParameterMultipleValueSupport": null,
  "ProtoDefinitions": null,
  "GraphQLSchemas": null,
  "AdminPath": null
}
12/17/2025 11:51:44 PM [Info] : Server using .NET 8.0
12/17/2025 11:57:21 PM [Info] : By Stef Heyenrath (https://github.com/wiremock/WireMock.Net)
12/17/2025 11:57:21 PM [Debug] : Server settings {
  "Port": null,
  "UseSSL": null,
  "HostingScheme": null,
  "UseHttp2": null,
  "StartAdminInterface": null,
  "ReadStaticMappings": null,
  "WatchStaticMappings": null,
  "WatchStaticMappingsInSubdirectories": null,
  "ProxyAndRecordSettings": null,
  "Urls": null,
  "StartTimeout": 10000,
  "AllowPartialMapping": null,
  "AdminUsername": null,
  "AdminPassword": null,
  "AdminAzureADTenant": null,
  "AdminAzureADAudience": null,
  "RequestLogExpirationDuration": 6,
  "MaxRequestLogCount": 100,
  "CorsPolicyOptions": null,
  "AllowCSharpCodeMatcher": null,
  "AllowBodyForAllHttpMethods": null,
  "AllowOnlyDefinedHttpStatusCodeInResponse": null,
  "DisableJsonBodyParsing": null,
  "DisableRequestBodyDecompressing": null,
  "DisableDeserializeFormUrlEncoded": null,
  "HandleRequestsSynchronously": null,
  "CertificateSettings": null,
  "CustomCertificateDefined": false,
  "ClientCertificateMode": 0,
  "AcceptAnyClientCertificate": false,
  "WebhookSettings": null,
  "UseRegexExtended": true,
  "SaveUnmatchedRequests": true,
  "DoNotSaveDynamicResponseInLogEntry": null,
  "QueryParameterMultipleValueSupport": null,
  "ProtoDefinitions": null,
  "GraphQLSchemas": null,
  "AdminPath": null,
  "HandlebarsSettings": null
}
12/17/2025 11:57:21 PM [Info] : Server using .NET 8.0

Is there a way to turn on logging for requests/responses? Thank you in advance!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions