We have common BL classes in a ASP.NET Core application that get in the ctor:
Microsoft.Extensions.Logging.ILogger
In ASP.NET Core, the i
I would recommend a slightly different approach if you want to register ir manually direct on Autofac:
private static void ConfigureLogging(ILoggingBuilder log)
{
log.ClearProviders();
log.SetMinimumLevel(LogLevel.Error);
log.AddConsole();
}
private static void ConfigureContainer(ContainerBuilder builder)
{
builder.Register(handler => LoggerFactory.Create(ConfigureLogging))
.As()
.SingleInstance()
.AutoActivate();
builder.RegisterGeneric(typeof(Logger<>))
.As(typeof(ILogger<>))
.SingleInstance();
// other registrations
}
And this on you main startup code:
var containerBuilder = new ContainerBuilder();
ConfigureContainer(containerBuilder);
var container = containerBuilder.Build();
var serviceProvider = new AutofacServiceProvider(container);
// you can use either the built container or set the serviceProvider onto the library you are using.