描述
log4net配置正确,但是没有日志输出。
示例代码:
ILog log = LogManager.GetLogger(this.GetType());
log.Warn("bussinessException"); // 没有输出
分析
log4net配置文件所在Assembly 与 LogManager.GetLogger 方法指定的Assembly 不一致。LogManager.GetLogger方法有多个重载,一些重载的方法内部是通过Assembly.GetCallingAssembly()获取的Assembly ,假如你的获取ILog 实例的代码与日志输出的代码不在同一个程序集时可能出现该问题。
解决方式
给GetLogger方法指定正确的Assembly
实例代码:
ILog log = LogManager.GetLogger(this.GetType().Assembly, this.GetType());
log.Warn("bussinessException"); // 搞定