< Summary

Information
Class: Elsa.Diagnostics.StructuredLogs.Services.StructuredLogFilterEvaluator
Assembly: Elsa.Diagnostics.StructuredLogs
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.StructuredLogs/Services/StructuredLogFilterEvaluator.cs
Line coverage
71%
Covered lines: 28
Uncovered lines: 11
Coverable lines: 39
Total lines: 70
Line coverage: 71.7%
Branch coverage
72%
Covered branches: 48
Total branches: 66
Branch coverage: 72.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Matches(...)63.88%1243659.25%
EqualsFilter(...)100%22100%
StartsWith(...)100%22100%
Contains(...)75%44100%
ContainsText(...)81.81%2222100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.StructuredLogs/Services/StructuredLogFilterEvaluator.cs

#LineLine coverage
 1using Elsa.Diagnostics.StructuredLogs.Models;
 2
 3namespace Elsa.Diagnostics.StructuredLogs.Services;
 4
 5public static class StructuredLogFilterEvaluator
 6{
 7    public static bool Matches(StructuredLogEvent logEvent, StructuredLogFilter filter)
 8    {
 199        if (filter.MinimumLevel is { } minimumLevel && logEvent.Level < minimumLevel)
 010            return false;
 11
 1912        if (filter.Levels?.Count > 0 && !filter.Levels.Contains(logEvent.Level))
 013            return false;
 14
 1915        if (!StartsWith(logEvent.Category, filter.CategoryPrefix))
 116            return false;
 17
 1818        if (!ContainsText(logEvent, filter.Text))
 019            return false;
 20
 1821        if (!EqualsFilter(logEvent.TenantId, filter.TenantId))
 022            return false;
 23
 1824        if (!EqualsFilter(logEvent.WorkflowDefinitionId, filter.WorkflowDefinitionId))
 025            return false;
 26
 1827        if (!EqualsFilter(logEvent.WorkflowInstanceId, filter.WorkflowInstanceId))
 028            return false;
 29
 1830        if (!EqualsFilter(logEvent.TraceId, filter.TraceId))
 031            return false;
 32
 1833        if (!EqualsFilter(logEvent.SpanId, filter.SpanId))
 034            return false;
 35
 1836        if (!EqualsFilter(logEvent.CorrelationId, filter.CorrelationId))
 037            return false;
 38
 1839        if (!EqualsFilter(logEvent.SourceId, filter.SourceId))
 340            return false;
 41
 1542        if (filter.From is { } from && logEvent.Timestamp < from)
 043            return false;
 44
 1545        if (filter.To is { } to && logEvent.Timestamp > to)
 046            return false;
 47
 1548        return true;
 49    }
 50
 12651    private static bool EqualsFilter(string? value, string? filter) => string.IsNullOrWhiteSpace(filter) || string.Equal
 52
 1953    private static bool StartsWith(string value, string? filter) => string.IsNullOrWhiteSpace(filter) || value.StartsWit
 54
 1655    private static bool Contains(string? value, string? filter) => string.IsNullOrWhiteSpace(filter) || value?.Contains(
 56
 57    private static bool ContainsText(StructuredLogEvent logEvent, string? filter)
 58    {
 1859        if (string.IsNullOrWhiteSpace(filter))
 1460            return true;
 61
 462        return Contains(logEvent.Message, filter)
 463               || Contains(logEvent.MessageTemplate, filter)
 464               || Contains(logEvent.Category, filter)
 465               || Contains(logEvent.Exception?.Message, filter)
 466               || Contains(logEvent.Exception?.StackTrace, filter)
 167               || logEvent.Properties.Any(x => Contains(x.Key, filter) || Contains(x.Value, filter))
 568               || logEvent.Scopes.Any(x => Contains(x.Key, filter) || Contains(x.Value, filter));
 69    }
 70}