欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

过滤掉Abp框架不需要记录的日志

程序员文章站 2022-10-24 12:49:02
该文章是系列文章 "基于.NetCore和ABP框架如何让Windows服务执行Quartz定时作业" 的其中一篇。 问题 "ABP.WindowsService/Demo.MyJob/4.0.0" 该项目不仅包含了Job服务,还有一个Abp项目自动生成的web站点服务。之前改造了job的日志记录, ......

该文章是系列文章 基于.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

什么原因导致的呢?分析过程,如下

解决方案:
修改log4net.config配置文件
原配置内容

  <root>
    <level value="debug" />
    <appender-ref ref="rollingfile" />
  </root>

修改为

  <root>
    <level value="info" />
    <appender-ref ref="rollingfile" />
  </root>

启动验证一下,正常运行之后发现不需要记录的日志都已经过滤掉了。