< Summary

Information
Class: TeleFlow.Framework.Middleware.UpdateLoggingMiddleware
Assembly: TeleFlow.Framework.Core
File(s): /_/src/TeleFlow.Framework.Core/Middleware/UpdateLoggingMiddleware.cs
Line coverage
83%
Covered lines: 26
Uncovered lines: 5
Coverable lines: 31
Total lines: 66
Line coverage: 83.8%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor()100%210%
.ctor(...)100%11100%
InvokeAsync()66.66%7669.23%

File(s)

/_/src/TeleFlow.Framework.Core/Middleware/UpdateLoggingMiddleware.cs

#LineLine coverage
 1using Microsoft.Extensions.Logging;
 2using TeleFlow.Framework.Updates;
 3
 4namespace TeleFlow.Framework.Middleware;
 5
 6public sealed class UpdateLoggingMiddleware : IUpdateMiddleware
 7{
 18    private static readonly Action<ILogger, Exception?> LogProcessingStarted =
 19        LoggerMessage.Define(
 110            LogLevel.Information,
 111            new EventId(1, nameof(LogProcessingStarted)),
 112            "Started processing update.");
 13
 114    private static readonly Action<ILogger, Exception?> LogProcessingFinished =
 115        LoggerMessage.Define(
 116            LogLevel.Information,
 117            new EventId(2, nameof(LogProcessingFinished)),
 118            "Finished processing update.");
 19
 120    private static readonly Action<ILogger, Exception?> LogProcessingFailed =
 121        LoggerMessage.Define(
 122            LogLevel.Error,
 123            new EventId(3, nameof(LogProcessingFailed)),
 124            "Failed processing update.");
 25
 26    private readonly ILogger<UpdateLoggingMiddleware>? _logger;
 27
 28    public UpdateLoggingMiddleware()
 29    {
 030    }
 31
 32    public UpdateLoggingMiddleware(ILogger<UpdateLoggingMiddleware> logger)
 33    {
 134        _logger = logger;
 135    }
 36
 37    public async Task InvokeAsync(UpdateContext context, UpdateDelegate next)
 38    {
 139        ArgumentNullException.ThrowIfNull(context);
 140        ArgumentNullException.ThrowIfNull(next);
 41
 142        if (_logger is not null)
 43        {
 144            LogProcessingStarted(_logger, null);
 45        }
 46
 47        try
 48        {
 149            await next(context).ConfigureAwait(false);
 50
 151            if (_logger is not null)
 52            {
 153                LogProcessingFinished(_logger, null);
 54            }
 155        }
 056        catch (Exception exception)
 57        {
 058            if (_logger is not null)
 59            {
 060                LogProcessingFailed(_logger, exception);
 61            }
 62
 063            throw;
 64        }
 165    }
 66}