how to add configuration for log4net (or any other 3rd party library) in ASP.NET 5.0

為{幸葍}努か 提交于 2019-12-05 01:16:38

Recently I had the same problem with log4net. I managed to do it working as following:

Create log4net.xml file containing the configuration section for log4net

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
...
</log4net>

You can put the file in the project root folder.

And in the Startup.Startup() method you can configure the log4net providing the xml as a configuration:

public Startup(IApplicationEnvironment appEnv)
{
    // ... 

    XmlConfigurator.Configure(new FileInfo(Path.Combine(appEnv.ApplicationBasePath, "log4net.xml")));
}

I hope this helps.

Current versions of log4net don't support Json projects, so the config needs to be in a separate xml file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!