New: Additional logging for InvalidModel BadRequest API calls

pull/2558/head
Qstick 3 years ago
parent d12ba05466
commit 150d7b046a

@ -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<ApiBehaviorOptions>(options =>
{
var builtInFactory = options.InvalidModelStateResponseFactory;
options.InvalidModelStateResponseFactory = context =>
{
var loggerFactory = context.HttpContext.RequestServices.GetRequiredService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger(context.ActionDescriptor.DisplayName);
logger.LogError(STJson.ToJson(context.ModelState));
return builtInFactory(context);
};
});
}
public void Configure(IApplicationBuilder app,

Loading…
Cancel
Save