Adding request-response logging to a file #405

Closed
opened 2025-12-29 15:22:53 +01:00 by adam · 3 comments
Owner

Originally created by @ZenwalkerD on GitHub (Feb 11, 2022).

I am using wiremock.net in my .NET CORE 5 project as shown:

server = WireMockServer.Start(new WireMockServerSettings()
            {
                Urls = new[] { WireMockUrl },
                StartAdminInterface = true,
                AllowCSharpCodeMatcher = true
            });

server.Given(Request.Create().WithPath("/hello"))
               .RespondWith(Response.Create()
               .WithStatusCode(System.Net.HttpStatusCode.OK));

I want to have a log written to a file; whenever /hello path is hit by any client. How to do this? I searched wiki and also library; i could not find.

Thanks

Originally created by @ZenwalkerD on GitHub (Feb 11, 2022). I am using wiremock.net in my .NET CORE 5 project as shown: ``` c# server = WireMockServer.Start(new WireMockServerSettings() { Urls = new[] { WireMockUrl }, StartAdminInterface = true, AllowCSharpCodeMatcher = true }); server.Given(Request.Create().WithPath("/hello")) .RespondWith(Response.Create() .WithStatusCode(System.Net.HttpStatusCode.OK)); ``` I want to have a log written to a file; whenever /hello path is hit by any client. How to do this? I searched wiki and also library; i could not find. Thanks
adam added the question label 2025-12-29 15:22:53 +01:00
adam closed this issue 2025-12-29 15:22:53 +01:00
Author
Owner

@StefH commented on GitHub (Feb 11, 2022):

@ZenwalkerD
Currently there is no logic or callback functionality implemented which allows this.

BTW: your question looks a lot like this one: #723

@StefH commented on GitHub (Feb 11, 2022): @ZenwalkerD Currently there is no logic or callback functionality implemented which allows this. BTW: your question looks a lot like this one: #723
Author
Owner

@StefH commented on GitHub (May 21, 2022):

@ZenwalkerD
Actually there is simple solution.

You can just implement your own logger, like:
https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Service/WireMockLog4NetLogger.cs
And you use the public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest) to write the requests / responses.

@StefH commented on GitHub (May 21, 2022): @ZenwalkerD Actually there is simple solution. You can just implement your own logger, like: https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Service/WireMockLog4NetLogger.cs And you use the `public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)` to write the requests / responses.
Author
Owner

@ZenwalkerD commented on GitHub (May 23, 2022):

@ZenwalkerD Actually there is simple solution.

You can just implement your own logger, like: https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Service/WireMockLog4NetLogger.cs And you use the public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest) to write the requests / responses.

But which builder method should i use to do the invocation? In the code i have shown; none of then methods provdes any method which would give all the details like what is being returned; which http method, etc details.

@ZenwalkerD commented on GitHub (May 23, 2022): > @ZenwalkerD Actually there is simple solution. > > You can just implement your own logger, like: https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Service/WireMockLog4NetLogger.cs And you use the `public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)` to write the requests / responses. But which builder method should i use to do the invocation? In the code i have shown; none of then methods provdes any method which would give all the details like what is being returned; which http method, etc details.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#405