net core配置log4net需要注意的地方

论坛 期权论坛 脚本     
匿名技术用户   2021-1-2 16:23   302   0

和netframework不一样的是,netcore 没有assembly文件。所以配置的时候需要注意:

1.配置文件可以没有

<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
  </configSections>

这一段代码。

2.要保证 LogManager.GetLogger(typeof(Respository));在

 var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

这两句之后执行,可以加到startup的构造函数里,参考:

https://stackify.com/making-log4net-net-core-work/

3.记得在Startup类加入[assembly: XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]标记

其中2和3步骤是保证IsErrorEnabled等属性不为false的关键

转载于:https://www.cnblogs.com/llcdbk/p/11270915.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP