< Summary

Information
Class: EF.Blockchain.Server.Middleware.RequestLoggingMiddleware
Assembly: EF.Blockchain.Server
File(s): C:\dev\@web3\web3-001-ef-blockchain\backend\EF.Blockchain\src\EF.Blockchain.Server\Middleware\RequestLoggingMiddleware.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 34
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Invoke()100%22100%

File(s)

C:\dev\@web3\web3-001-ef-blockchain\backend\EF.Blockchain\src\EF.Blockchain.Server\Middleware\RequestLoggingMiddleware.cs

#LineLine coverage
 1using Serilog;
 2
 3namespace EF.Blockchain.Server.Middleware;
 4
 5public class RequestLoggingMiddleware
 6{
 7    private readonly RequestDelegate _next;
 8
 2249    public RequestLoggingMiddleware(RequestDelegate next) => _next = next;
 10
 11    public async Task Invoke(HttpContext context)
 8812    {
 8813        var method = context.Request.Method;
 8814        var path = context.Request.Path;
 15
 8816        context.Request.EnableBuffering();
 8817        string body = "";
 18
 8819        if (context.Request.ContentLength > 0)
 3220        {
 3221            context.Request.Body.Position = 0;
 3222            using var reader = new StreamReader(context.Request.Body, leaveOpen: true);
 3223            body = await reader.ReadToEndAsync();
 3224            context.Request.Body.Position = 0;
 3225        }
 26
 8827        var start = DateTime.Now;
 8828        await _next(context);
 8829        var duration = DateTime.Now - start;
 30
 8831        Log.Information("{Method} {Path} => {StatusCode} ({Duration} ms) | Body: {Body}",
 8832            method, path, context.Response.StatusCode, duration.TotalMilliseconds, body);
 8833    }
 34}