1. 程式人生 > >過濾掉Abp框架不需要記錄的日誌

過濾掉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>

啟動驗證一下,正常執行之後發現不需要記錄的日誌都已經過濾掉了