在程序开发中,日志记录是必不可少的,为了能够记录程序异常、程序运行性能等。
下面是我在工作中对log4net扩展封装
需要源码的可以关注私信我,相互学习提高
![f97a657053c3aa80cb01b0c881c099d2.png](https://i-blog.csdnimg.cn/blog_migrate/411182aa5254b8d2cd29237d4650e934.jpeg)
首页引用第三方包:log4net
![37376bae49a7d325b18691cef28a8afe.png](https://i-blog.csdnimg.cn/blog_migrate/92b1d46766198d502eb7593c251c1663.jpeg)
- 添加 log4net配置文件 log4net.config
<?xml version="1.0" encoding="utf-8" ?>
- 添加Log4Net工厂
using log4net;using System;using System.Collections.Generic;using System.Linq;using System.Runtime.CompilerServices;using System.Text;using System.Threading.Tasks;namespace NCore.Extensions.Log4NetEX{ public class NCoreLoggerFactory : NCore.Logging.ILoggerFactory { public Logging.ILogger GetCurrentClassLogger() { return new NCoreLogger(LogManager.GetLogger(Extensions.repository.Name, "NETCorelog4net")); } public Logging.ILogger GetCurrentClassLogger(Type loggerType) { return new NCoreLogger(LogManager.GetLogger(Extensions.repository.Name,loggerType)); } public Logging.ILogger GetLogger(string name) { return new NCoreLogger(LogManager.GetLogger(Extensions.repository.Name, name)); } public Logging.ILogger GetLogger(s