a9bea183c1
- IContextualSerilogLogger<T> / ContextualSerilogLogger<T> in Services/Logging (handlers get a ForContext<T>-scoped logger via DI, consistent with ItemTracker) - SerilogRegistrar extension on WebApplicationBuilder (Api) - SerilogRegistrar extension on HostApplicationBuilder (Worker) - Both registrars: set Log.Logger, wire Logging + Host/Services, register ILogger singleton - ServiceCollectionExtensions: register IContextualSerilogLogger<> as transient - Program.cs in both apps simplified to single builder.AddSerilog() call Ref: IT-628 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
23 lines
744 B
C#
23 lines
744 B
C#
using HrynCo.NotificationService.Services.Behaviors;
|
|
using HrynCo.NotificationService.Services.Logging;
|
|
using MediatR;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace HrynCo.NotificationService.Services;
|
|
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddNotificationServices(this IServiceCollection services)
|
|
{
|
|
services.AddMediatR(cfg =>
|
|
{
|
|
cfg.RegisterServicesFromAssembly(typeof(ServiceCollectionExtensions).Assembly);
|
|
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(TransactionBehavior<,>));
|
|
});
|
|
|
|
services.AddTransient(typeof(IContextualSerilogLogger<>), typeof(ContextualSerilogLogger<>));
|
|
|
|
return services;
|
|
}
|
|
}
|