using Elsa.Diagnostics.ConsoleLogs.Contracts; using Elsa.Diagnostics.ConsoleLogs.Services; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; namespace Elsa.Diagnostics.ConsoleLogs.Extensions; public static class HostServiceCollectionExtensions { /// /// Registers the host-level console capture pipeline. Call this from Program.cs (ideally right /// after ConsoleStreamHook.Install()) so that the capture singleton, the in-memory ring buffer, /// the source registry, and the idle flush loop are owned by the root host rather than by any /// individual shell. /// /// /// Shell-level features that surface console logs (REST endpoints, SignalR hub) still call /// AddConsoleLogsServices on their own service collection — those registrations resolve to the /// same host-owned singletons exposed by . /// /// public static IServiceCollection AddConsoleLogsHost(this IServiceCollection services, Action? configure = null) { ConsoleStreamHook.Install(); if (configure != null) ConsoleLogsHost.Configure(configure); services.TryAddSingleton(_ => ConsoleLogsHost.ScopeAccessor); services.AddSingleton(sp => sp.GetRequiredService()); #pragma warning disable CS0618 services.TryAddSingleton(); #pragma warning restore CS0618 services.TryAddEnumerable(ServiceDescriptor.Singleton()); return services; } }