diff --git a/src/NzbDrone.Host/Startup.cs b/src/NzbDrone.Host/Startup.cs index b94d25e9f..e8a57b1d4 100644 --- a/src/NzbDrone.Host/Startup.cs +++ b/src/NzbDrone.Host/Startup.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.HttpOverrides; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -110,6 +111,21 @@ namespace NzbDrone.Host }); services.AddAppAuthentication(); + + services.PostConfigure(options => + { + var builtInFactory = options.InvalidModelStateResponseFactory; + + options.InvalidModelStateResponseFactory = context => + { + var loggerFactory = context.HttpContext.RequestServices.GetRequiredService(); + var logger = loggerFactory.CreateLogger(context.ActionDescriptor.DisplayName); + + logger.LogError(STJson.ToJson(context.ModelState)); + + return builtInFactory(context); + }; + }); } public void Configure(IApplicationBuilder app,