johnkors / MinimalHttpLogger

Reduces no. of HttpClient log statements from 4 to 1 pr request (Microsoft.Extensions.Http)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MinimalHttpLogger

Build NuGet NuGet

Why?

My logs were

  • hard to read
  • filling up space(*)

What is this?

It's not possible to configure the log pattern of the Microsoft.Extensions.Http based HttpClient loggers. To modify, one has to replace them. This package replaces the default loggers with a logger that:

  1. Reduces the number of log statements on httpclient requests from 4 to 1
  2. Logs 1 aggregated log statement: {Method} {Uri} - {StatusCode} {StatusCodeLiteral} in {Time}ms

Change in output

Before:

info: Start processing HTTP request GET https://www.google.com/
info: Sending HTTP request GET https://www.google.com/
info: Received HTTP response headers after 188.6041ms - 200
info: End processing HTTP request after 188.8026ms - 200

After:

info: GET https://www.google.com/ - 200 OK in 186.4883ms

Install

$ dotnet add package MinimalHttpLogger

Usage

services.UseMinimalHttpLogger();

(*) I'm cheap. My Papertrail account stops logging when reaching a certain szie, so reducing the log helps

About

Reduces no. of HttpClient log statements from 4 to 1 pr request (Microsoft.Extensions.Http)

License:MIT License


Languages

Language:C# 100.0%