2026-05-18 00:16:46 +00:00
|
|
|
using CShells.AspNetCore.Features;
|
|
|
|
|
using CShells.FastEndpoints.Features;
|
|
|
|
|
using CShells.Features;
|
2026-05-26 22:14:28 +00:00
|
|
|
using ConsoleLogStreaming.Core.Options;
|
2026-05-18 00:16:46 +00:00
|
|
|
using Elsa.Diagnostics.ConsoleLogs.Extensions;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Microsoft.AspNetCore.Routing;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Diagnostics.ConsoleLogs.ShellFeatures;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provides live raw console log streaming over REST and SignalR.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ShellFeature(
|
|
|
|
|
DisplayName = "Console Logs",
|
|
|
|
|
Description = "Provides live raw console log streaming over REST and SignalR",
|
2026-05-26 22:14:28 +00:00
|
|
|
DependsOn = ["ElsaFastEndpoints", "Workflows"])]
|
2026-05-18 00:16:46 +00:00
|
|
|
[UsedImplicitly]
|
|
|
|
|
public class ConsoleLogsFeature : IFastEndpointsShellFeature, IWebShellFeature
|
|
|
|
|
{
|
2026-05-26 22:14:28 +00:00
|
|
|
private static readonly ConsoleLogOptions DefaultOptions = new();
|
2026-05-18 00:16:46 +00:00
|
|
|
|
2026-05-26 22:14:28 +00:00
|
|
|
public int RecentLogCapacity { get; set; } = DefaultOptions.RecentCapacity;
|
|
|
|
|
public int SubscriberChannelCapacity { get; set; } = DefaultOptions.SubscriberCapacity;
|
2026-05-18 00:16:46 +00:00
|
|
|
public int CaptureChannelCapacity { get; set; } = DefaultOptions.CaptureChannelCapacity;
|
|
|
|
|
public int MaxRecentQuerySize { get; set; } = DefaultOptions.MaxRecentQuerySize;
|
|
|
|
|
public int MaxLineLength { get; set; } = DefaultOptions.MaxLineLength;
|
|
|
|
|
public TimeSpan IdleFlushTimeout { get; set; } = DefaultOptions.IdleFlushTimeout;
|
2026-05-26 22:14:28 +00:00
|
|
|
public bool StripAnsiEscapeSequences { get; set; } = !DefaultOptions.PreserveAnsi;
|
2026-05-18 00:16:46 +00:00
|
|
|
public TimeSpan SourceHeartbeatTimeout { get; set; } = DefaultOptions.SourceHeartbeatTimeout;
|
|
|
|
|
public string RedactionReplacement { get; set; } = DefaultOptions.RedactionReplacement;
|
|
|
|
|
public ICollection<string> SensitiveNames { get; set; } = [..DefaultOptions.SensitiveNames];
|
2026-05-26 22:14:28 +00:00
|
|
|
public ICollection<string> SensitiveTextPatterns { get; set; } = [..DefaultOptions.RedactionRules.Select(x => x.Pattern)];
|
2026-05-18 00:16:46 +00:00
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddConsoleLogsServices(ConfigureOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MapEndpoints(IEndpointRouteBuilder endpoints, IHostEnvironment? environment)
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapConsoleLogsHub();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-26 22:14:28 +00:00
|
|
|
private void ConfigureOptions(ConsoleLogOptions options)
|
2026-05-18 00:16:46 +00:00
|
|
|
{
|
2026-05-26 22:14:28 +00:00
|
|
|
options.RecentCapacity = RecentLogCapacity;
|
|
|
|
|
options.SubscriberCapacity = SubscriberChannelCapacity;
|
2026-05-18 00:16:46 +00:00
|
|
|
options.CaptureChannelCapacity = CaptureChannelCapacity;
|
|
|
|
|
options.MaxRecentQuerySize = MaxRecentQuerySize;
|
|
|
|
|
options.MaxLineLength = MaxLineLength;
|
|
|
|
|
options.IdleFlushTimeout = IdleFlushTimeout;
|
2026-05-26 22:14:28 +00:00
|
|
|
options.PreserveAnsi = !StripAnsiEscapeSequences;
|
2026-05-18 00:16:46 +00:00
|
|
|
options.SourceHeartbeatTimeout = SourceHeartbeatTimeout;
|
|
|
|
|
options.RedactionReplacement = RedactionReplacement;
|
|
|
|
|
options.SensitiveNames = [..SensitiveNames];
|
2026-05-26 22:14:28 +00:00
|
|
|
options.RedactionRules.Clear();
|
|
|
|
|
foreach (var pattern in SensitiveTextPatterns)
|
|
|
|
|
{
|
|
|
|
|
options.RedactionRules.Add(new()
|
|
|
|
|
{
|
|
|
|
|
Name = "Sensitive text",
|
|
|
|
|
Pattern = pattern,
|
|
|
|
|
Replacement = RedactionReplacement
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-05-18 00:16:46 +00:00
|
|
|
}
|
|
|
|
|
}
|