I am trying to replace dryIOC container with autofac container for some reason but I don't know the exact syntax how could I resolve ILogger uisng autofac
Here is how I register ILogger in DryIoc
public void Load(IContainer container)
{
container.Register<ILoggerFactory, Log4NetLoggerFactory>();
ConfigureLogger(container);
}
[Localizable(false)]
private void ConfigureLogger(IContainer container)
{
container.Register<ILogger>(
made: Made.Of(
r => typeof(ILoggerFactory).GetMethod(nameof(ILoggerFactory.Create), new[] { typeof(Type) }),
factoryInfo: ServiceInfo.Of<ILoggerFactory>(),
parameters: Parameters.Of.Name("type", r => r.Parent?.ImplementationType ?? typeof(Startup))),
reuse: Reuse.Transient);
}
I have tried something like this, but it does not work with Autofac
container.Register<ILoggerFactory, Log4NetLoggerFactory>();
If you try to resolve an instance of
Microsoft.Extensions.Logging.ILoggerthen you have two options:Option #1 - Resolve a
ILogger<TCategoryName>.Option #2 - Resolve an
ILoggerinstead ofILogger<TCategoryName>automatically.My nuget package does exactly this using Autofac:
EgonsoftHU.Extensions.Logging.Autofac
It contains an Autofac module. Register it then magic will happen.