diff --git a/src/BUTR.Site.NexusMods.Server/Controllers/ApiControllerBase.cs b/src/BUTR.Site.NexusMods.Server/Controllers/ApiControllerBase.cs index 53e1401d..7727762c 100644 --- a/src/BUTR.Site.NexusMods.Server/Controllers/ApiControllerBase.cs +++ b/src/BUTR.Site.NexusMods.Server/Controllers/ApiControllerBase.cs @@ -13,9 +13,12 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Routing; +using Microsoft.Extensions.Logging; namespace BUTR.Site.NexusMods.Server.Controllers; @@ -107,6 +110,13 @@ protected ApiResult ApiResult(int statusCode = StatusCodes.Status204NoContent) [NonAction] protected ApiResult ApiResultError(string error, int statusCode) { + var routeAttribute = Url.ActionContext.ActionDescriptor.EndpointMetadata.OfType().First(); + var routeTemplate = routeAttribute.Template; + + var loggerFactory = HttpContext.RequestServices.GetRequiredService(); + var logger = loggerFactory.CreateLogger(GetType()); + logger.LogError("Route: {Route}, API Error: {Error}", routeTemplate, error); + if (statusCode is < 400 or >= 600) throw new ArgumentOutOfRangeException(nameof(statusCode));