< Summary

Information
Class: NexusLabs.Needlr.Serilog.SerilogPlugin
Assembly: NexusLabs.Needlr.Serilog
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Serilog/SerilogPlugin.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 42
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Configure(...)100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Serilog/SerilogPlugin.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.Logging;
 3
 4using Serilog;
 5
 6namespace NexusLabs.Needlr.Serilog;
 7
 8/// <summary>
 9/// Auto-discovered plugin that wires Serilog as the logging provider using
 10/// configuration from <c>appsettings.json</c> (or any <see cref="Microsoft.Extensions.Configuration.IConfiguration"/>
 11/// source registered with Needlr).
 12/// </summary>
 13/// <remarks>
 14/// <para>
 15/// This plugin provides a zero-ceremony default: reference the
 16/// <c>NexusLabs.Needlr.Serilog</c> package and add a <c>"Serilog"</c> section
 17/// to <c>appsettings.json</c>. The plugin is auto-discovered and configures
 18/// <see cref="ILogger{TCategoryName}"/> resolution via DI.
 19/// </para>
 20/// <para>
 21/// The Serilog logger is owned by the DI container — sinks flush automatically
 22/// on container disposal. The static <see cref="Log.Logger"/> is not set — use
 23/// <see cref="ILogger{TCategoryName}"/> injection instead, or use
 24/// <see cref="NeedlrSerilogBootstrapper"/> for apps that need the static logger
 25/// and two-stage bootstrap lifecycle.
 26/// </para>
 27/// </remarks>
 28public sealed class SerilogPlugin : IServiceCollectionPlugin
 29{
 30    public void Configure(ServiceCollectionPluginOptions options)
 31    {
 1332        var logger = new LoggerConfiguration()
 1333            .ReadFrom.Configuration(options.Config)
 1334            .CreateLogger();
 35
 1336        options.Services.AddLogging(builder =>
 1337        {
 1338            builder.ClearProviders();
 1339            builder.AddSerilog(logger, dispose: true);
 2640        });
 1341    }
 42}