【发布时间】:2019-06-26 20:19:30
【问题描述】:
我正在使用 ASP.NET Core 2.2 开发 API 服务器,我的服务器机器是 Ubuntu 18.04。
我有一个关于我的 API 状态的日志文件,但我觉得缺少 ASP.NET(Kestrel) 状态信息,例如路由结果到我的控制器。
ASP.NET 生成如下日志。
ServerApplication> info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
ServerApplication> Request starting HTTP/1.1 GET
http://localhost:57904/api
ServerApplication> info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
ServerApplication> Request starting HTTP/1.1 DEBUG
http://localhost:57904/ 0
ServerApplication> info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
ServerApplication> Request finished in 36.827ms 200
ServerApplication> info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
我想收听或捕获这些日志以放入我的日志文件。
我读过this article,但似乎不是在谈论听日志。
如何解决这个问题?
【问题讨论】:
-
您可以试用 Serilog ,它为您提供了多种选项来丰富和记录不同格式和目的地的事件。
-
@SoumenMukherjee 我有自己的日志记录 API,我不觉得这很糟糕。我只想知道 Kestrel 的状态。不记录 API。
-
所以我看到您编写了自己的自定义事件接收器.. 好..
标签: c# asp.net-core asp.net-core-webapi