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


和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的關鍵


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM