我试图在ASP.Net Core应用程序中运行Log4net,到目前为止有问题。
我在AppSettings.json
中获得了第二行"log4netConfig": "log4net\logConfiguration.xml"
and在startup.cs
中log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(string.Concat(env.ContentRootPath, @"", loggingConfig["log4netConfig"])));
至少在本地机器上似乎有效,但是发布后,我收到第二个错误:
Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
所以...据我了解,尚未建立配置。我还为所有包含 XmlConfigurator.Configure()
的项目的手工制作的记录仪,这对我所理解的这些事情非常不好(它过去正常工作,直到我需要在appsettings.json中移动log4net file路径。
我该更改如何使这件事正常工作?
好吧,问题最终是这样的:
XmlConfigurator.Configure()
在我自己的记录器中,并在startup.cs中添加了 .AddSingleton
。似乎Logger尝试在app.config中找到log4net.config键(不再存在),最终成为此问题。
我更改了配置调用和繁荣,没有更多错误...