Files
CBDD/tests/CBDD.Tests.Benchmark/Infrastructure/Logging.cs
Joseph Doherty 4c6aaa5a3f
All checks were successful
NuGet Publish / build-and-pack (push) Successful in 46s
NuGet Publish / publish-to-gitea (push) Successful in 53s
Implement checkpoint modes with docs/tests and reorganize project file layout
2026-02-21 07:56:36 -05:00

39 lines
1.1 KiB
C#

using Microsoft.Extensions.Logging;
using Serilog;
namespace ZB.MOM.WW.CBDD.Tests.Benchmark;
internal static class Logging
{
private static readonly Lazy<ILoggerFactory> LoggerFactoryInstance = new(CreateFactory);
/// <summary>
/// Gets the shared logger factory for benchmarks.
/// </summary>
public static ILoggerFactory LoggerFactory => LoggerFactoryInstance.Value;
/// <summary>
/// Creates a logger for the specified category type.
/// </summary>
/// <typeparam name="T">The logger category type.</typeparam>
/// <returns>A logger for <typeparamref name="T"/>.</returns>
public static Microsoft.Extensions.Logging.ILogger CreateLogger<T>()
{
return LoggerFactory.CreateLogger<T>();
}
private static ILoggerFactory CreateFactory()
{
var serilogLogger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();
return Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>
{
builder.ClearProviders();
builder.AddSerilog(serilogLogger, dispose: true);
});
}
}