log4net:ERROR ConfigureFromXml called with null 'element' parameter

场景重现

ASP.NET Core 下集成 log4net 时, 运行时报错如下:

log4net:ERROR ConfigureFromXml called with null 'element' parameter

解决办法

找个一圈后, 发现是 log4net.config 的问题

<!-- log4net.config -->
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <log4net>
    <!-- more... -->
  <log4net>
<configuration>

去掉 <configuration> 节点, 让 <log4net> 作为最外层节点即可.

<!-- log4net.config -->
<?xml version="1.0" encoding="utf-8"?>
<log4net>
  <!-- more... -->
<log4net>

后续

但是 Visual Studio 小哥会丢个波浪线和警告出来, 令人懊恼, 何解?

参考

猜你喜欢

转载自www.cnblogs.com/taadis/p/log4net-error-configurefromxml-called-with-null-element-parameter.html