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

Open
opened 2025-12-29 08:33:09 +01:00 by adam · 2 comments
Owner

Originally created by @Swimburger on GitHub (Dec 18, 2025).

Originally assigned to: @StefH on GitHub.

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!

Originally created by @Swimburger on GitHub (Dec 18, 2025). Originally assigned to: @StefH on GitHub. 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: ```csharp 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: ```csharp 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!
adam added the question label 2025-12-29 08:33:09 +01:00
Author
Owner

@StefH commented on GitHub (Dec 20, 2025):

@Swimburger
It could be that logging in a unit test does not work correct.

In that case you can create your own implementation like this:

// Copyright © WireMock.Net

using System;
using JsonConverter.Abstractions;
using JsonConverter.Newtonsoft.Json;
using NUnit.Framework;
using WireMock.Admin.Requests;
using WireMock.Logging;

namespace WireMock.Net.NUnit;

/// <summary>
/// When using NUnit, this class enables to log the output from WireMock.Net using the <see cref="TestContext"/>.
/// </summary>
public sealed class TestContextWireMockLogger(IJsonConverter? jsonConverter = null) : IWireMockLogger
{
    private readonly JsonConverterOptions _jsonConverterOptions = new() { WriteIndented = true, IgnoreNullValues = true };
    private readonly IJsonConverter _jsonConverter = jsonConverter ?? new NewtonsoftJsonConverter();

    /// <inheritdoc />
    public void Debug(string formatString, params object[] args)
    {
        TestContext.WriteLine(Format("Debug", formatString, args));
    }

    /// <inheritdoc />
    public void Info(string formatString, params object[] args)
    {
        TestContext.WriteLine(Format("Info", formatString, args));
    }

    /// <inheritdoc />
    public void Warn(string formatString, params object[] args)
    {
        TestContext.WriteLine(Format("Warning", formatString, args));
    }

    /// <inheritdoc />
    public void Error(string formatString, params object[] args)
    {
        TestContext.WriteLine(Format("Error", formatString, args));
    }

    /// <inheritdoc />
    public void Error(string message, Exception exception)
    {
        TestContext.WriteLine(Format("Error", $"{message} {{0}}", exception));

        if (exception is AggregateException ae)
        {
            ae.Handle(ex =>
            {
                TestContext.WriteLine(Format("Error", "Exception {0}", ex));
                return true;
            });
        }
    }

    /// <inheritdoc />
    public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
    {
        var message = _jsonConverter.Serialize(logEntryModel, _jsonConverterOptions);
        TestContext.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message));
    }

    private static string Format(string level, string formatString, params object[] args)
    {
        var message = args.Length > 0 ? string.Format(formatString, args) : formatString;
        return $"{DateTime.UtcNow} [{level}] : {message}";
    }
}

--> Not that I'll create a new nuget for this class which can be used.

@StefH commented on GitHub (Dec 20, 2025): @Swimburger It could be that logging in a unit test does not work correct. In that case you can create your own implementation like this: ``` c# // Copyright © WireMock.Net using System; using JsonConverter.Abstractions; using JsonConverter.Newtonsoft.Json; using NUnit.Framework; using WireMock.Admin.Requests; using WireMock.Logging; namespace WireMock.Net.NUnit; /// <summary> /// When using NUnit, this class enables to log the output from WireMock.Net using the <see cref="TestContext"/>. /// </summary> public sealed class TestContextWireMockLogger(IJsonConverter? jsonConverter = null) : IWireMockLogger { private readonly JsonConverterOptions _jsonConverterOptions = new() { WriteIndented = true, IgnoreNullValues = true }; private readonly IJsonConverter _jsonConverter = jsonConverter ?? new NewtonsoftJsonConverter(); /// <inheritdoc /> public void Debug(string formatString, params object[] args) { TestContext.WriteLine(Format("Debug", formatString, args)); } /// <inheritdoc /> public void Info(string formatString, params object[] args) { TestContext.WriteLine(Format("Info", formatString, args)); } /// <inheritdoc /> public void Warn(string formatString, params object[] args) { TestContext.WriteLine(Format("Warning", formatString, args)); } /// <inheritdoc /> public void Error(string formatString, params object[] args) { TestContext.WriteLine(Format("Error", formatString, args)); } /// <inheritdoc /> public void Error(string message, Exception exception) { TestContext.WriteLine(Format("Error", $"{message} {{0}}", exception)); if (exception is AggregateException ae) { ae.Handle(ex => { TestContext.WriteLine(Format("Error", "Exception {0}", ex)); return true; }); } } /// <inheritdoc /> public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest) { var message = _jsonConverter.Serialize(logEntryModel, _jsonConverterOptions); TestContext.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message)); } private static string Format(string level, string formatString, params object[] args) { var message = args.Length > 0 ? string.Format(formatString, args) : formatString; return $"{DateTime.UtcNow} [{level}] : {message}"; } } ``` --> Not that I'll create a new nuget for this class which can be used.
Author
Owner

@StefH commented on GitHub (Dec 20, 2025):

https://github.com/wiremock/WireMock.Net/pull/1400

@StefH commented on GitHub (Dec 20, 2025): https://github.com/wiremock/WireMock.Net/pull/1400
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#734