.Net Core Using Middleware to log http request/responses

Chewy2Theo
1 min readMay 29, 2021

With .Net 4.7 I used to log my http request and response conditionally through the help of owin. However with .Net Core, they have a set of awesome middlewares that you can now override and make use of. All you need to do is create a middleware class and register it in the Configure method within the startup.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseHttpsRedirection(); app.UseMiddleware<HttpHandlerMiddleware>(); app.UseDefaultFiles();
app.UseStaticFiles();
}

So my middleware code looks like this:

The above code is constructed from the post below. Let’s render the credit to where it’s due.

This article is a part of the .Net to .Net Core Migration Series
https://theochiu2010.medium.com/net-to-net-core-migration-2eb31584f95c

--

--

Chewy2Theo

Just another developer who's into lazy tools that can make my life easier, and hopefully yours too.