6

I need to use log4net on a new .NET Core app that references some just written assemblies which uses log4net. I've searched around but all the examples passes just a FileInfo to the log4net.Config.XmlConfigurator.Configure but using the latest version asks for a first paremeter of type ILoggerRepository repository

What should I pass?

My code is

   public static void Main(string[] args)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json");

        var configuration = builder.Build();

        ContainerConfig.RegisterDependencies(configuration);
        MappingConfig.RegisterMapping();


        var fileInfo = new FileInfo(@"\config.log4net");

        log4net.Config.XmlConfigurator.Configure(null, fileInfo);



        var core = ContainerWrapper.Container.GetInstance<ICore>();

        core.StartAsync().Wait();

        Console.Write("Press a key to exit");
        Console.ReadLine();
    }

But with null it crashes

Any suggestions?

1 Answer 1

9

You can get the default repository via the statement here below,
and pass that one as argument of the Configure method.

ILoggerRepository repository = log4net.LogManager.GetRepository(Assembly.GetCallingAssembly());

Depending on your setup, you might need to use Assembly.GetExecutingAssembly() instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.