Intro
在 ASP.NET core 中有些日志我们可能想输出到数据库或文件或 Elasticsearch 等, 如果不自己去实现一个 LoggerProvider 的话就需要借助第三方日志框架实现了, 而一些第三方框架的实现大多比较完善和成熟, 不失为一个好办法.
自己写了一个 log4net 的扩展 , 提供了在 .net core 中使用 log4net 的扩展
安装 nuget 包
通过 nuget 安装
使用
基本使用
- ILoggerFactory loggerFactory = new LoggerFactory();
- loggerFactory.AddLog4Net(); // loggerFactory.AddLog4Net(log4netConfigFilePath);
你可以在 ASP.NET core 应用里你的 Startup 文件中使用下面代码进行配置
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder App, IHostingEnvironment env, ILoggerFactory loggerFactory)
- {
- loggerFactory.AddLog4Net(); // loggerFactory.AddLog4Net(log4netConfigFilePath);
- // ...
- }
默认使用当前目录下的 log4net.config 文件作为 log4net 的配置文件, 如果不是需要自己设置 log4net 配置文件的路径.
log4net 配置参考 示例配置
Memo
如果有什么问题或建议, 欢迎指出
来源: http://www.bubuko.com/infodetail-2971721.html