asp.net-core - 记录器的 FluentValidation 错误

标签 asp.net-core fluentvalidation

我正在注册我的 FluentValidation 验证器,如下所示:

services.AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<CustomRequestValidator>());

我如何处理任何验证错误以通过我的日志记录实现记录它们,例如串行?

最佳答案

对于遇到这个问题的用户(像我一样),我想提供我找到的解决方案。

实际问题是 ASP.NET Core,尤其是 API,使 Model State errors automatically trigger a 400 error response ,它不会记录验证错误。

在相同的文档下方,它们包括 instructions on how to enable automatic logging for that feature我认为这应该是解决这个问题的正确方法。

关于asp.net-core - 记录器的 FluentValidation 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57892394/

相关文章:

c# - 如何在 EF Core 2.1.0 中设置管理员用户?

c# - 模拟子验证器时 FluentValidation 抛出 NullReference 异常

c# - 您如何使用 Fluent Validation 对列表中的每个字符串进行验证?

c# - 不需要的文化特定 dll 复制到 bin 目录

asp.net-core - SignalR Core 未生成(映射)客户端方法

asp.net-core - ASP.Net Core 中联合身份验证的替代方法是什么?

c# - Blazor 和 Web API 解决方案中的 .NET Core 身份

c# - HTML Razor 中 Step 属性的自定义错误验证

asp.net-mvc - model.isvalid mvc servicestack 流畅验证

c# - 流利的验证集合项不为空/空