【发布时间】:2019-06-24 07:40:19
【问题描述】:
如果我使用dotnet new mvc 创建一个新的ASP.NET Core Web App (Model-View-Controller),它已经配置了开箱即用的日志记录。
但是,http 请求错误代码被记录为信息事件。
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET https://localhost:5001/doesnotexists
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 4.4052ms 404
是否可以将此行为更改为(4xx -> 警告,5xx -> 错误)。即通过调查和重写日志事件。
我已经看过https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.2
这看起来很有希望,但我没有找到用于此目的的钩子
var webHost = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureLogging((hostingContext, logging) =>
{
// investigate and rewrite log event
})
.UseStartup<Startup>()
.Build()
【问题讨论】:
标签: c# asp.net asp.net-core logging