0
kestrelのホスティングでクライアントのipsを記録する方法はありますか?私はアプリの設定でDEBUGログレベルを指定しましたが、依然として、誰からではなく、要求されているサーバーのパスだけを示しています。要求ごとにクライアントのIPを記録する - kestrelのアクセスログ
私はクライアントのipが各api内でHttpContext
の構造体から取得できることは知っていますが、私が望むのは、フレームワークによってログに記録して、各APIに同じ機能を追加することができます。
dbug: Microsoft.AspNetCore.Server.Kestrel[1]
Connection id "0HL9L7IJ7JLIV" started.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://192.168.1.110:2180/ <====== it logs the server path
dbug: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[9]
AuthenticationScheme: Bearer was not authenticated.
dbug: Microsoft.AspNetCore.Routing.RouteBase[1]
Request successfully matched the route with name 'default' and template '{controller}/{action}'.
dbug: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action CH.Api.Controllers.HomeController.Index (CH)
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method CH.Controllers.HomeController.Index (CH) with arguments ((null)) - ModelState is Valid
dbug: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
...
dbug: Microsoft.AspNetCore.Server.Kestrel[9]
Connection id "0HL9L7IJ7JLIV" completed keep alive response.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 160.2879ms 200 text/plain; charset=utf-8
dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv[6]
Connection id "0HL9L7IJ7JLIV" received FIN.
dbug: Microsoft.AspNetCore.Server.Kestrel[10]
Connection id "0HL9L7IJ7JLIV" disconnecting.
dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv[7]
Connection id "0HL9L7IJ7JLIV" sending FIN.
dbug: Microsoft.AspNetCore.Server.Kestrel[2]
Connection id "0HL9L7IJ7JLIV" stopped.
設定ファイルでそれを有効にするだけの方法がない場合、私はミドルウェアのパスに行きます。私は、nginxのように、あなたは設定ファイルによってaccess.logを行うことができます。 – fluter