Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working through Module #3

Open
sunnamed434 opened this issue Oct 7, 2022 · 0 comments
Open

Not working through Module #3

sunnamed434 opened this issue Oct 7, 2022 · 0 comments

Comments

@sunnamed434
Copy link

Module registration process

public class BitMonoApplication : IApplication
{
    public AutofacServiceProvider Build()
    {
        return Build(new BitMonoAutofacServicesRegistryModule());
    }
    public AutofacServiceProvider Build(IModule module)
    {
        var containerBuilder = new ContainerBuilder();
        containerBuilder.RegisterModule(module);
        var container = containerBuilder.Build();
        return new AutofacServiceProvider(container.Resolve<ILifetimeScope>());
    }
}
public class BitMonoAutofacServicesRegistryModule : Module
{
    protected override void Load(ContainerBuilder containerBuilder)
    {
       var currentAssemblyDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
       var file = Path.Combine(currentAssemblyDirectory, "logs", "bitMono-{Date}.log");

       containerBuilder.RegisterSerilog(new LoggerConfiguration()
            .WriteTo.Console()
            .WriteTo.RollingFile(file, shared: true));
    }
}

Resolving Logger

var container = new BitMonoApplication().Build();
var logger = container.LifetimeScope.Resolve<ILogger>();

Error:
image

Working fine in this case

containerBuilder.Register<ILogger>((c, p) =>
{
    return new LoggerConfiguration()
        .WriteTo.Console()
        .WriteTo.RollingFile(file, shared: true)
        .CreateLogger();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant