# Sprout.Log **Repository Path**: bi_miaomiao/Sprout.Log ## Basic Information - **Project Name**: Sprout.Log - **Description**: 封装log4net, json文件格式,方便elk采集。 同时模仿spring boot里autowire方式注入,方便使用. - **Primary Language**: C# - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-03-28 - **Last Updated**: 2021-03-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Sprout.Log #### 介绍 封装log4net, json文件格式,方便elk采集。 同时模仿spring boot里autowire方式注入,方便使用. #### 使用说明 1. nuget 搜索 Sprout.Log ,并安装 2. 项目文件中引入Log4net配置,配置如下 ```xml ``` 文件名为 log4net.config.xml,文件名一定要正确,否则启动会提示找不到配置文件名. 3. 搜索类库 Autowired.Core ,这个是模仿spring boot 中注解注入的东西,很好用。因为.net core默认容器不支持属性注入,很恶心人的构造函数用法实在无法容忍. 4. startup.cs中加入 ```c# //注册应用服务 services.AddAppServices(); //添加日志工具 services.AddSproutLog(Configuration); ``` Controller中使用示例 ```c# //这个是唯一遗憾的地方(spring boot中无需,),需要注意这个服务,后续所有服务都不需要构造函数注入 public HelloController(AutowiredService autowiredService) { autowiredService.Autowired(this); } //autowired 注入,哈哈spring boot中的灵魂 //终于告别 ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);裹脚布的写法了 [Autowired] private ILog _log; ``` 5. 项目源码地址 Sprout.Log:https://gitee.com/bi_miaomiao/Sprout.Log.git AutowiredCore:https://gitee.com/loogn/Autowired.Core ####