过滤掉Abp框架不需要记录的日志
该文章是系列文章 基于.NetCore和ABP框架如何让Windows服务执行Quartz定时作业 的其中一篇。
问题
ABP.WindowsService/Demo.MyJob/4.0.0该项目不仅包含了Job服务,还有一个Abp项目自动生成的web站点服务。之前改造了job的日志记录,之后尝试改造web站点。发现一个问题,就是每次启动都会生成类似下文的日志,但是这些日志都不是我主动记录的日志。那么显然,当你试图记录日志,下面的这些框架自动生成的诊断日志就会成为干扰。如何去除这些诊断日志呢?
DEBUG 2019-09-03 18:51:28,556 [1 ] Abp.Modules.AbpModuleManager - Loading Abp modules...
DEBUG 2019-09-03 18:51:28,928 [1 ] Abp.Modules.AbpModuleManager - Found 10 ABP modules in total.
DEBUG 2019-09-03 18:51:29,700 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.Web.Startup.MyJobWebModule, Demo.MyJob.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,704 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.MyJobApplicationModule, Demo.MyJob.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,705 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.MyJobCoreModule, Demo.MyJob.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,707 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AutoMapper.AbpAutoMapperModule, Abp.AutoMapper, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,707 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AbpKernelModule, Abp, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,707 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.EntityFrameworkCore.MyJobEntityFrameworkCoreModule, Demo.MyJob.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,707 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule, Abp.EntityFrameworkCore, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,708 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.EntityFramework.AbpEntityFrameworkCommonModule, Abp.EntityFramework.Common, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,708 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AspNetCore.AbpAspNetCoreModule, Abp.AspNetCore, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,708 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Web.AbpWebCommonModule, Abp.Web.Common, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:29,711 [1 ] Abp.Modules.AbpModuleManager - 10 modules loaded.
DEBUG 2019-09-03 18:51:30,517 [1 ] ameworkCore.AbpEntityFrameworkCoreModule - Registering DbContext: Demo.MyJob.EntityFrameworkCore.MyJobDbContext, Demo.MyJob.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 18:51:30,912 [1 ] Abp.Localization.LocalizationManager - Initializing 3 localization sources.
DEBUG 2019-09-03 18:51:31,069 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: Abp
DEBUG 2019-09-03 18:51:31,372 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: MyJob
DEBUG 2019-09-03 18:51:31,419 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: AbpWeb
DEBUG 2019-09-03 18:51:31,944 [1 ] Abp.BackgroundJobs.BackgroundJobManager - Start background worker: Castle.Proxies.BackgroundJobManagerProxy
DEBUG 2019-09-03 18:51:32,019 [1 ] Abp.AutoMapper.AbpAutoMapperModule - Found 0 classes define auto mapping attributes
INFO 2019-09-03 18:51:33,581 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/
INFO 2019-09-03 18:51:33,581 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 DEBUG http://localhost:62114/ 0
INFO 2019-09-03 18:51:33,673 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 90.7012ms 200
INFO 2019-09-03 18:51:34,194 [7 ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {action = "Index", controller = "Home", area = ""}. Executing action Demo.MyJob.Web.Controllers.HomeController.Index (Demo.MyJob.Web)
INFO 2019-09-03 18:51:34,292 [7 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Demo.MyJob.Web.Controllers.HomeController.Index (Demo.MyJob.Web) - Validation state: Valid
INFO 2019-09-03 18:51:34,300 [7 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action method Demo.MyJob.Web.Controllers.HomeController.Index (Demo.MyJob.Web), returned result Microsoft.AspNetCore.Mvc.ViewResult in 5.1007ms.
INFO 2019-09-03 18:51:34,318 [7 ] Abp.Auditing.SimpleLogAuditingStore - AUDIT LOG: Demo.MyJob.Web.Controllers.HomeController.Index is executed by an anonymous user in 47 ms from ::1 IP address with succeed.
INFO 2019-09-03 18:51:34,395 [7 ] Core.Mvc.ViewFeatures.ViewResultExecutor - Executing ViewResult, running view Index.
INFO 2019-09-03 18:51:34,806 [7 ] Core.Mvc.ViewFeatures.ViewResultExecutor - Executed ViewResult - view Index executed in 468.7549ms.
INFO 2019-09-03 18:51:34,812 [7 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action Demo.MyJob.Web.Controllers.HomeController.Index (Demo.MyJob.Web) in 613.974ms
INFO 2019-09-03 18:51:34,825 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 1250.0712ms 200 text/html; charset=utf-8
INFO 2019-09-03 18:51:34,991 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/sweetalert/dist/sweetalert.css
INFO 2019-09-03 18:51:34,991 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/toastr/toastr.css
INFO 2019-09-03 18:51:35,051 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/font-awesome/css/font-awesome.css
INFO 2019-09-03 18:51:35,085 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/bootstrap-paper/bootstrap.css
INFO 2019-09-03 18:51:35,109 [6 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/sweetalert/dist/sweetalert.css'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\sweetalert\dist\sweetalert.css'
INFO 2019-09-03 18:51:35,114 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/css/main.css
INFO 2019-09-03 18:51:35,114 [9 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/font-awesome/css/font-awesome.css'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\font-awesome\css\font-awesome.css'
INFO 2019-09-03 18:51:35,164 [8 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/css/main.css'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\css\main.css'
INFO 2019-09-03 18:51:35,166 [7 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/toastr/toastr.css'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\toastr\toastr.css'
INFO 2019-09-03 18:51:35,169 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 177.5574ms 200 text/css
INFO 2019-09-03 18:51:35,169 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 177.8087ms 200 text/css
INFO 2019-09-03 18:51:35,169 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/famfamfam-flags/dist/sprite/famfamfam-flags.css
INFO 2019-09-03 18:51:35,169 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 54.5501ms 200 text/css
INFO 2019-09-03 18:51:35,169 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 117.3342ms 200 text/css
INFO 2019-09-03 18:51:35,190 [6 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/famfamfam-flags/dist/sprite/famfamfam-flags.css'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\famfamfam-flags\dist\sprite\famfamfam-flags.css'
INFO 2019-09-03 18:51:35,190 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 20.6735ms 200 text/css
INFO 2019-09-03 18:51:35,257 [7 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/bootstrap-paper/bootstrap.css'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\bootstrap-paper\bootstrap.css'
INFO 2019-09-03 18:51:35,257 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 172.137ms 200 text/css
INFO 2019-09-03 18:51:35,283 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/moment/min/moment-with-locales.js
INFO 2019-09-03 18:51:35,286 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/json2/json2.js
INFO 2019-09-03 18:51:35,297 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/jquery-validation/dist/jquery.validate.js
INFO 2019-09-03 18:51:35,298 [7 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/json2/json2.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\json2\json2.js'
INFO 2019-09-03 18:51:35,300 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 14.5734ms 200 application/javascript
INFO 2019-09-03 18:51:35,300 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/bootstrap/dist/js/bootstrap.js
INFO 2019-09-03 18:51:35,305 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/jquery/dist/jquery.js
INFO 2019-09-03 18:51:35,327 [8 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/jquery-validation/dist/jquery.validate.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\jquery-validation\dist\jquery.validate.js'
INFO 2019-09-03 18:51:35,327 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 29.4745ms 200 application/javascript
INFO 2019-09-03 18:51:35,369 [9 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/bootstrap/dist/js/bootstrap.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\bootstrap\dist\js\bootstrap.js'
INFO 2019-09-03 18:51:35,370 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 69.1099ms 200 application/javascript
INFO 2019-09-03 18:51:35,372 [10 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/toastr/toastr.js
INFO 2019-09-03 18:51:35,373 [6 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/toastr/toastr.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\toastr\toastr.js'
INFO 2019-09-03 18:51:35,373 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 1.1496ms 200 application/javascript
INFO 2019-09-03 18:51:35,395 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/blockUI/jquery.blockUI.js
INFO 2019-09-03 18:51:35,400 [10 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/blockUI/jquery.blockUI.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\blockUI\jquery.blockUI.js'
INFO 2019-09-03 18:51:35,400 [10 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 4.7696ms 200 application/javascript
INFO 2019-09-03 18:51:35,440 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/sweetalert/dist/sweetalert-dev.js
INFO 2019-09-03 18:51:35,443 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/spin.js/jquery.spin.js
INFO 2019-09-03 18:51:35,445 [8 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/spin.js/jquery.spin.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\spin.js\jquery.spin.js'
INFO 2019-09-03 18:51:35,445 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 2.6389ms 200 application/javascript
INFO 2019-09-03 18:51:35,446 [8 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/jquery/dist/jquery.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\jquery\dist\jquery.js'
INFO 2019-09-03 18:51:35,446 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 140.3229ms 200 application/javascript
INFO 2019-09-03 18:51:35,447 [10 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/spin.js/spin.js
INFO 2019-09-03 18:51:35,451 [8 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/sweetalert/dist/sweetalert-dev.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\sweetalert\dist\sweetalert-dev.js'
INFO 2019-09-03 18:51:35,451 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 11.1469ms 200 application/javascript
INFO 2019-09-03 18:51:35,521 [8 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/spin.js/spin.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\spin.js\spin.js'
INFO 2019-09-03 18:51:35,521 [10 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.blockUI.js
INFO 2019-09-03 18:51:35,521 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 73.7904ms 200 application/javascript
INFO 2019-09-03 18:51:35,521 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.toastr.js
INFO 2019-09-03 18:51:35,521 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/abp-web-resources/Abp/Framework/scripts/abp.js
INFO 2019-09-03 18:51:35,521 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.jquery.js
INFO 2019-09-03 18:51:35,522 [10 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.blockUI.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\abp-web-resources\Abp\Framework\scripts\libs\abp.blockUI.js'
INFO 2019-09-03 18:51:35,522 [6 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/abp-web-resources/Abp/Framework/scripts/abp.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\abp-web-resources\Abp\Framework\scripts\abp.js'
INFO 2019-09-03 18:51:35,522 [10 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 1.7359ms 200 application/javascript
INFO 2019-09-03 18:51:35,523 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 1.4094ms 200 application/javascript
INFO 2019-09-03 18:51:35,525 [8 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.toastr.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\abp-web-resources\Abp\Framework\scripts\libs\abp.toastr.js'
INFO 2019-09-03 18:51:35,525 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 3.6857ms 200 application/javascript
INFO 2019-09-03 18:51:35,526 [7 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.jquery.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\abp-web-resources\Abp\Framework\scripts\libs\abp.jquery.js'
INFO 2019-09-03 18:51:35,526 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 5.0962ms 200 application/javascript
INFO 2019-09-03 18:51:35,555 [9 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/moment/min/moment-with-locales.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\moment\min\moment-with-locales.js'
INFO 2019-09-03 18:51:35,555 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 272.0541ms 200 application/javascript
INFO 2019-09-03 18:51:35,579 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.sweet-alert.js
INFO 2019-09-03 18:51:35,589 [9 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.sweet-alert.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\abp-web-resources\Abp\Framework\scripts\libs\abp.sweet-alert.js'
INFO 2019-09-03 18:51:35,589 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 10.0396ms 200 application/javascript
INFO 2019-09-03 18:51:35,589 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/AbpScripts/GetScripts?v=637031334947750684
INFO 2019-09-03 18:51:35,591 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.spin.js
INFO 2019-09-03 18:51:35,592 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/AbpServiceProxies/GetAll?v=637031334947741174
INFO 2019-09-03 18:51:35,594 [8 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/abp-web-resources/Abp/Framework/scripts/libs/abp.spin.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\abp-web-resources\Abp\Framework\scripts\libs\abp.spin.js'
INFO 2019-09-03 18:51:35,595 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 3.413ms 200 application/javascript
INFO 2019-09-03 18:51:35,597 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/js/views/home/index.js
INFO 2019-09-03 18:51:35,601 [8 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/js/views/home/index.js'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\js\views\home\index.js'
INFO 2019-09-03 18:51:35,601 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 4.6526ms 200 application/javascript
INFO 2019-09-03 18:51:35,627 [9 ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {action = "GetScripts", controller = "AbpScripts", area = ""}. Executing action Abp.AspNetCore.Mvc.Controllers.AbpScriptsController.GetScripts (Abp.AspNetCore)
INFO 2019-09-03 18:51:35,632 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/famfamfam-flags/dist/sprite/famfamfam-flags.png
INFO 2019-09-03 18:51:35,633 [6 ] ore.Mvc.Internal.ControllerActionInvoker - Route matched with {action = "GetAll", controller = "AbpServiceProxies", area = ""}. Executing action Abp.AspNetCore.Mvc.Proxying.AbpServiceProxiesController.GetAll (Abp.AspNetCore)
INFO 2019-09-03 18:51:35,725 [9 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Abp.AspNetCore.Mvc.Controllers.AbpScriptsController.GetScripts (Abp.AspNetCore) with arguments (, False) - Validation state: Valid
INFO 2019-09-03 18:51:35,730 [7 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/famfamfam-flags/dist/sprite/famfamfam-flags.png'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\famfamfam-flags\dist\sprite\famfamfam-flags.png'
INFO 2019-09-03 18:51:35,730 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 97.6549ms 200 image/png
INFO 2019-09-03 18:51:35,787 [6 ] ore.Mvc.Internal.ControllerActionInvoker - Executing action method Abp.AspNetCore.Mvc.Proxying.AbpServiceProxiesController.GetAll (Abp.AspNetCore) with arguments (Abp.AspNetCore.Mvc.Proxying.ApiProxyGenerationModel) - Validation state: Valid
INFO 2019-09-03 18:51:35,789 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/lib/font-awesome/fonts/fontawesome-webfont.woff2?v=4.6.3
INFO 2019-09-03 18:51:35,819 [7 ] NetCore.StaticFiles.StaticFileMiddleware - Sending file. Request path: '/lib/font-awesome/fonts/fontawesome-webfont.woff2'. Physical path: 'D:\GitHub\DotNetCore_Practice\ABP.WindowsService\Demo.MyJob\4.0.0\src\Demo.MyJob.Web\wwwroot\lib\font-awesome\fonts\fontawesome-webfont.woff2'
INFO 2019-09-03 18:51:35,823 [7 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 33.8363ms 200 font/woff2
INFO 2019-09-03 18:51:35,924 [6 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action method Abp.AspNetCore.Mvc.Proxying.AbpServiceProxiesController.GetAll (Abp.AspNetCore), returned result Microsoft.AspNetCore.Mvc.ContentResult in 135.5736ms.
INFO 2019-09-03 18:51:35,936 [6 ] Mvc.Infrastructure.ContentResultExecutor - Executing ContentResult with HTTP Response ContentType of application/x-javascript
INFO 2019-09-03 18:51:35,937 [6 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action Abp.AspNetCore.Mvc.Proxying.AbpServiceProxiesController.GetAll (Abp.AspNetCore) in 304.1108ms
INFO 2019-09-03 18:51:35,937 [6 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 345.5179ms 200 application/x-javascript
INFO 2019-09-03 18:51:35,982 [9 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action method Abp.AspNetCore.Mvc.Controllers.AbpScriptsController.GetScripts (Abp.AspNetCore), returned result Microsoft.AspNetCore.Mvc.ContentResult in 256.5804ms.
INFO 2019-09-03 18:51:35,982 [9 ] Mvc.Infrastructure.ContentResultExecutor - Executing ContentResult with HTTP Response ContentType of application/x-javascript; charset=utf-8
INFO 2019-09-03 18:51:35,982 [9 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action Abp.AspNetCore.Mvc.Controllers.AbpScriptsController.GetScripts (Abp.AspNetCore) in 354.8506ms
INFO 2019-09-03 18:51:35,982 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 392.9551ms 200 application/x-javascript; charset=utf-8
INFO 2019-09-03 18:51:36,186 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://localhost:62114/favicon.ico
INFO 2019-09-03 18:51:36,189 [9 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 3.4275ms 404
日志打印不全
先解决日志打印不全的问题。
这个问题跟log4net.config有关。
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %date [%-5.5thread] %-40.40logger - %message%newline" />
</layout>
%-40.40logger
的意思是日志左对齐,若日志器的名称小于 40 个字符,则右边补空格。若日志器名称的长度大于 40 个字符,则截取。更多格式化配置请参考log4net.Layout.PatternLayout 用 conversion 模式格式化日志事件【翻译】 – 船长&CAP – 博客园。
所以可以将上述配置改为
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5level %date [%-5.5thread] %c - %message%newline" />
</layout>
即只打印出日志器名称即可。
日志过滤
查询官方文档 .NET Core 和 ASP.NET Core 中的日志记录 | Microsoft Docs
查看源码 AspNetCore/HostingApplicationDiagnostics.cs at master · aspnet/AspNetCore
看到下述逻辑
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void BeginRequest(HttpContext httpContext, HostingApplication.Context context)
{
long startTimestamp = 0;
if (HostingEventSource.Log.IsEnabled())
{
context.EventLogEnabled = true;
// To keep the hot path short we defer logging in this function to non-inlines
RecordRequestStartEventLog(httpContext);
}
var diagnosticListenerEnabled = _diagnosticListener.IsEnabled();
var loggingEnabled = _logger.IsEnabled(LogLevel.Critical);
if (loggingEnabled || (diagnosticListenerEnabled && _diagnosticListener.IsEnabled(ActivityName, httpContext)))
{
context.Activity = StartActivity(httpContext, out var hasDiagnosticListener);
context.HasDiagnosticListener = hasDiagnosticListener;
}
if (diagnosticListenerEnabled)
{
if (_diagnosticListener.IsEnabled(DeprecatedDiagnosticsBeginRequestKey))
{
startTimestamp = Stopwatch.GetTimestamp();
RecordBeginRequestDiagnostics(httpContext, startTimestamp);
}
}
// To avoid allocation, return a null scope if the logger is not on at least to some degree.
if (loggingEnabled)
{
// Scope may be relevant for a different level of logging, so we always create it
// see: https://github.com/aspnet/Hosting/pull/944
// Scope can be null if logging is not on.
context.Scope = _logger.RequestScope(httpContext, context.Activity);
if (_logger.IsEnabled(LogLevel.Information))
{
if (startTimestamp == 0)
{
startTimestamp = Stopwatch.GetTimestamp();
}
// Non-inline
LogRequestStarting(context);
}
}
context.StartTimestamp = startTimestamp;
}
有这样一行代码var loggingEnabled = _logger.IsEnabled(LogLevel.Critical);
,又文档 .NET Core 和 ASP.NET Core 中的日志记录 | Microsoft Docs中提到
要禁止显示所有日志,可将 LogLevel.None 指定为最低日志级别。 LogLevel.None 的整数值为 6,它大于 LogLevel.Critical (5)。
所以分析之后得出了两种过滤方案。
官方文档提供的两种方案如下。
一种是代码中进行配置。
改造之前
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
改造之后
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.ConfigureLogging(logging =>
logging
.AddFilter("System", LogLevel.None)
.AddFilter("Microsoft", LogLevel.None)
)
.Build();
host.Run();
}
}
可以看到是ConfigureLogging在起作用,这里使用LogLevel.None
级别,效果如下,只打印出了Abp的审计日志。
DEBUG 2019-09-03 20:02:21,753 [1 ] Abp.Modules.AbpModuleManager - Loading Abp modules...
DEBUG 2019-09-03 20:02:21,824 [1 ] Abp.Modules.AbpModuleManager - Found 10 ABP modules in total.
DEBUG 2019-09-03 20:02:22,003 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.Web.Startup.MyJobWebModule, Demo.MyJob.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,010 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.MyJobApplicationModule, Demo.MyJob.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,011 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.MyJobCoreModule, Demo.MyJob.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,013 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AutoMapper.AbpAutoMapperModule, Abp.AutoMapper, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,016 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AbpKernelModule, Abp, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,018 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.EntityFrameworkCore.MyJobEntityFrameworkCoreModule, Demo.MyJob.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,018 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule, Abp.EntityFrameworkCore, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,019 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.EntityFramework.AbpEntityFrameworkCommonModule, Abp.EntityFramework.Common, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,020 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AspNetCore.AbpAspNetCoreModule, Abp.AspNetCore, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,021 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Web.AbpWebCommonModule, Abp.Web.Common, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,024 [1 ] Abp.Modules.AbpModuleManager - 10 modules loaded.
DEBUG 2019-09-03 20:02:22,249 [1 ] Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule - Registering DbContext: Demo.MyJob.EntityFrameworkCore.MyJobDbContext, Demo.MyJob.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:02:22,457 [1 ] Abp.Localization.LocalizationManager - Initializing 3 localization sources.
DEBUG 2019-09-03 20:02:22,526 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: Abp
DEBUG 2019-09-03 20:02:22,991 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: MyJob
DEBUG 2019-09-03 20:02:23,024 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: AbpWeb
DEBUG 2019-09-03 20:02:23,293 [1 ] Abp.BackgroundJobs.BackgroundJobManager - Start background worker: Castle.Proxies.BackgroundJobManagerProxy
DEBUG 2019-09-03 20:02:23,351 [1 ] Abp.AutoMapper.AbpAutoMapperModule - Found 0 classes define auto mapping attributes
INFO 2019-09-03 20:02:25,645 [6 ] Abp.Auditing.SimpleLogAuditingStore - AUDIT LOG: Demo.MyJob.Web.Controllers.HomeController.Index is executed by an anonymous user in 121 ms from ::1 IP address with succeed.
一种是配置文件指定日志级别
appsettings.json文件修改之前关于日志的配置如下
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
日志指定None级别
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "None",
"System": "None",
"Microsoft": "None"
}
}
Web站点添加nuget包 NuGet Gallery | Microsoft.Extensions.Logging.Configuration 2.2.0
修改入口代码
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostingContext, config) =>
{
var hostingEnvironment = hostingContext.HostingEnvironment;
config.AddJsonFile("appsettings.json", true, true)
.AddJsonFile("appsettings." + hostingEnvironment.EnvironmentName + ".json", true, true);
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
})
.Build();
host.Run();
}
如果你的web站点的sdk版本是2.2,可以使用WebHost.CreateDefaultBuilder()
,创建默认的WebHostBuilder,该方法默认了上述的配置。源码请查看 AspNetCore/WebHost.cs at master · aspnet/AspNetCore。该方法在Microsoft.AspNetCore.App中,请引用包 NuGet Gallery | Microsoft.AspNetCore.App 2.2.0。
去掉Abp审计日志
在MyJobWebModule的方法PreInitialize中关闭审计日志
Configuration.Auditing.IsEnabled = false;
去掉审计日志之后发现启动Abp框架的时候还是有日志记录下来,日志内容如下
DEBUG 2019-09-03 20:42:34,063 [1 ] Abp.Modules.AbpModuleManager - Loading Abp modules...
DEBUG 2019-09-03 20:42:34,129 [1 ] Abp.Modules.AbpModuleManager - Found 10 ABP modules in total.
DEBUG 2019-09-03 20:42:34,147 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.Web.Startup.MyJobWebModule, Demo.MyJob.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,170 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.MyJobApplicationModule, Demo.MyJob.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,171 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.MyJobCoreModule, Demo.MyJob.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,172 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AutoMapper.AbpAutoMapperModule, Abp.AutoMapper, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,173 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AbpKernelModule, Abp, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,174 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Demo.MyJob.EntityFrameworkCore.MyJobEntityFrameworkCoreModule, Demo.MyJob.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,174 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule, Abp.EntityFrameworkCore, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,175 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.EntityFramework.AbpEntityFrameworkCommonModule, Abp.EntityFramework.Common, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,178 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.AspNetCore.AbpAspNetCoreModule, Abp.AspNetCore, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,179 [1 ] Abp.Modules.AbpModuleManager - Loaded module: Abp.Web.AbpWebCommonModule, Abp.Web.Common, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,185 [1 ] Abp.Modules.AbpModuleManager - 10 modules loaded.
DEBUG 2019-09-03 20:42:34,460 [1 ] Abp.EntityFrameworkCore.AbpEntityFrameworkCoreModule - Registering DbContext: Demo.MyJob.EntityFrameworkCore.MyJobDbContext, Demo.MyJob.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
DEBUG 2019-09-03 20:42:34,704 [1 ] Abp.Localization.LocalizationManager - Initializing 3 localization sources.
DEBUG 2019-09-03 20:42:34,775 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: Abp
DEBUG 2019-09-03 20:42:34,942 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: MyJob
DEBUG 2019-09-03 20:42:34,980 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: AbpWeb
DEBUG 2019-09-03 20:42:35,324 [1 ] Abp.BackgroundJobs.BackgroundJobManager - Start background worker: Castle.Proxies.BackgroundJobManagerProxy
DEBUG 2019-09-03 20:42:35,368 [1 ] Abp.AutoMapper.AbpAutoMapperModule - Found 0 classes define auto mapping attributes
什么原因导致的呢?分析过程,如下
- 发现上述日志都是DEBUG日志
- 推断Abp框架启动日志记录级别为DEBUG
- 验证推论,查看源码 aspnetboilerplate/AbpModuleManager.cs at master · aspnetboilerplate/aspnetboilerplate,从代码
Logger.Debug("Loading Abp modules...");
可以得出推论正确。
解决方案:
修改log4net.config配置文件
原配置内容
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</root>
修改为
<root>
<level value="INFO" />
<appender-ref ref="RollingFile" />
</root>
启动验证一下,正常运行之后发现不需要记录的日志都已经过滤掉了。