| | | 1 | | using CShells.AspNetCore.Features; |
| | | 2 | | using CShells.FastEndpoints.Features; |
| | | 3 | | using CShells.Features; |
| | | 4 | | using Elsa.Diagnostics.StructuredLogs.Extensions; |
| | | 5 | | using Elsa.Diagnostics.StructuredLogs.Options; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | using Microsoft.AspNetCore.Routing; |
| | | 8 | | using Microsoft.Extensions.DependencyInjection; |
| | | 9 | | using Microsoft.Extensions.Hosting; |
| | | 10 | | |
| | | 11 | | namespace Elsa.Diagnostics.StructuredLogs.ShellFeatures; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Provides live structured log streaming over REST and SignalR. |
| | | 15 | | /// </summary> |
| | | 16 | | [ShellFeature( |
| | | 17 | | DisplayName = "Structured Logs", |
| | | 18 | | Description = "Provides live structured log streaming over REST and SignalR", |
| | | 19 | | DependsOn = ["ElsaFastEndpoints"])] |
| | | 20 | | [UsedImplicitly] |
| | | 21 | | public class StructuredLogsFeature : IFastEndpointsShellFeature, IWebShellFeature |
| | | 22 | | { |
| | 1 | 23 | | private static readonly StructuredLogsOptions DefaultOptions = new(); |
| | | 24 | | |
| | 4 | 25 | | public int RecentLogCapacity { get; set; } = DefaultOptions.RecentLogCapacity; |
| | 4 | 26 | | public int SubscriberChannelCapacity { get; set; } = DefaultOptions.SubscriberChannelCapacity; |
| | 4 | 27 | | public int MaxRecentLogQuerySize { get; set; } = DefaultOptions.MaxRecentLogQuerySize; |
| | 4 | 28 | | public TimeSpan SourceHeartbeatTimeout { get; set; } = DefaultOptions.SourceHeartbeatTimeout; |
| | 4 | 29 | | public bool IncludeStructuredLogsInternalLogs { get; set; } = DefaultOptions.IncludeStructuredLogsInternalLogs; |
| | 4 | 30 | | public ICollection<string> SensitiveNames { get; set; } = [..DefaultOptions.SensitiveNames]; |
| | 4 | 31 | | public ICollection<string> SensitiveTextPatterns { get; set; } = [..DefaultOptions.SensitiveTextPatterns]; |
| | | 32 | | |
| | | 33 | | public void ConfigureServices(IServiceCollection services) |
| | | 34 | | { |
| | 1 | 35 | | services.AddStructuredLogsServices(ConfigureOptions); |
| | 1 | 36 | | } |
| | | 37 | | |
| | | 38 | | public void MapEndpoints(IEndpointRouteBuilder endpoints, IHostEnvironment? environment) |
| | | 39 | | { |
| | 0 | 40 | | endpoints.MapStructuredLogsHub(); |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | private void ConfigureOptions(StructuredLogsOptions options) |
| | | 44 | | { |
| | 1 | 45 | | options.RecentLogCapacity = RecentLogCapacity; |
| | 1 | 46 | | options.SubscriberChannelCapacity = SubscriberChannelCapacity; |
| | 1 | 47 | | options.MaxRecentLogQuerySize = MaxRecentLogQuerySize; |
| | 1 | 48 | | options.SourceHeartbeatTimeout = SourceHeartbeatTimeout; |
| | 1 | 49 | | options.IncludeStructuredLogsInternalLogs = IncludeStructuredLogsInternalLogs; |
| | 1 | 50 | | options.SensitiveNames = [..SensitiveNames]; |
| | 1 | 51 | | options.SensitiveTextPatterns = [..SensitiveTextPatterns]; |
| | 1 | 52 | | } |
| | | 53 | | } |