Files
jdescopingtool/NEW/tests/Utils/JdeScoping.ConfigManager.Cli.Tests/TestLoggingHelper.cs
T
Joseph Doherty 6f3e12b3b4 refactor(configmanager): convert CLI to structured logging with Serilog
Replace Console.WriteLine calls with ILogger usage across all CLI commands.
Serilog is configured via DI with clean message-only output suitable for
CLI tooling. Log levels map to --quiet (Warning), default (Information),
and --verbose (Debug) flags.

- Add Serilog packages and configure in Program.cs
- Convert all 7 command files to use ILoggerFactory from DI
- Add BeginScope with context properties (Command, ConfigPath, etc.)
- Create logging_style.md documenting patterns and best practices
- Update tests with TestLoggingHelper for Serilog test configuration
2026-01-28 15:53:08 -05:00

28 lines
919 B
C#

using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Serilog.Events;
namespace JdeScoping.ConfigManager.Cli.Tests;
/// <summary>
/// Helper for setting up logging in CLI tests.
/// </summary>
public static class TestLoggingHelper
{
/// <summary>
/// Adds Serilog logging to a service collection configured to write to Console.
/// This allows tests to capture log output via Console.SetOut.
/// </summary>
public static IServiceCollection AddTestLogging(this IServiceCollection services, LogEventLevel level = LogEventLevel.Information)
{
var logger = new LoggerConfiguration()
.MinimumLevel.Is(level)
.WriteTo.Console(outputTemplate: "{Message:lj}{NewLine}{Exception}")
.CreateLogger();
services.AddLogging(builder => builder.AddSerilog(logger, dispose: true));
return services;
}
}