I think I tried all possible combinations of calls to make log4net working woth ASP.NET Core 2.1 but no luck so far. I followed steps described in How to use log4net in Asp.net core 2.0 . I also explored all variants described in ASP.NET Core 2.1 + Log4Net.
No luck so far. The log4net.config is copied to the binary folder. It is used (I noticed it being locked when service is running). I used absolute and relative paths. Called and not called loggerFactory.AddLog4Net("log4net.config"); I called both:
var log4netConfig = new System.Xml.XmlDocument();
log4netConfig.Load(File.OpenRead(@"log4net.config"));
var repo = LogManager.CreateRepository(Assembly.GetEntryAssembly(), typeof(log4net.Repository.Hierarchy.Hierarchy));
XmlConfigurator.Configure(repo, log4netConfig["log4net"]);
and
ILoggerRepository repository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
ILog is created in the following way:
private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
But also I used this approach:
var log2 = LogManager.GetLogger(typeof(Startup));
log2.Info("SOME");
Each time log does not have any Appenders created (list is empty) even though Configure method is called.
Of course no file is created. I noticed that some people reported that it can be added to your Core 2.1 project but I haven't discovered yet the right permutation of calls and actions.
Is there a way to trace what is actually log4net doing to be able to fix the problem? So far in my long experience log4net had been the most difficult component to work with. Or an exact combination of steps? I am using log4net 2.0.8 nuget.