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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With