< 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
100%
Covered lines: 39
Uncovered lines: 0
Coverable lines: 39
Total lines: 70
Line coverage: 100%
Branch coverage
92%
Covered branches: 61
Total branches: 66
Branch coverage: 92.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Matches(...)100%3636100%
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    {
 729        if (filter.MinimumLevel is { } minimumLevel && logEvent.Level < minimumLevel)
 110            return false;
 11
 7112        if (filter.Levels?.Count > 0 && !filter.Levels.Contains(logEvent.Level))
 213            return false;
 14
 6915        if (!StartsWith(logEvent.Category, filter.CategoryPrefix))
 316            return false;
 17
 6618        if (!ContainsText(logEvent, filter.Text))
 219            return false;
 20
 6421        if (!EqualsFilter(logEvent.TenantId, filter.TenantId))
 222            return false;
 23
 6224        if (!EqualsFilter(logEvent.WorkflowDefinitionId, filter.WorkflowDefinitionId))
 225            return false;
 26
 6027        if (!EqualsFilter(logEvent.WorkflowInstanceId, filter.WorkflowInstanceId))
 228            return false;
 29
 5830        if (!EqualsFilter(logEvent.TraceId, filter.TraceId))
 231            return false;
 32
 5633        if (!EqualsFilter(logEvent.SpanId, filter.SpanId))
 234            return false;
 35
 5436        if (!EqualsFilter(logEvent.CorrelationId, filter.CorrelationId))
 237            return false;
 38
 5239        if (!EqualsFilter(logEvent.SourceId, filter.SourceId))
 540            return false;
 41
 4742        if (filter.From is { } from && logEvent.Timestamp < from)
 143            return false;
 44
 4645        if (filter.To is { } to && logEvent.Timestamp > to)
 246            return false;
 47
 4448        return true;
 49    }
 50
 40651    private static bool EqualsFilter(string? value, string? filter) => string.IsNullOrWhiteSpace(filter) || string.Equal
 52
 6953    private static bool StartsWith(string value, string? filter) => string.IsNullOrWhiteSpace(filter) || value.StartsWit
 54
 2755    private static bool Contains(string? value, string? filter) => string.IsNullOrWhiteSpace(filter) || value?.Contains(
 56
 57    private static bool ContainsText(StructuredLogEvent logEvent, string? filter)
 58    {
 6659        if (string.IsNullOrWhiteSpace(filter))
 5960            return true;
 61
 762        return Contains(logEvent.Message, filter)
 763               || Contains(logEvent.MessageTemplate, filter)
 764               || Contains(logEvent.Category, filter)
 765               || Contains(logEvent.Exception?.Message, filter)
 766               || Contains(logEvent.Exception?.StackTrace, filter)
 167               || logEvent.Properties.Any(x => Contains(x.Key, filter) || Contains(x.Value, filter))
 868               || logEvent.Scopes.Any(x => Contains(x.Key, filter) || Contains(x.Value, filter));
 69    }
 70}