Add Serilog console logging across the API

Information at endpoint and service-method boundaries, Debug in deeper
helpers, Warning before expected/recoverable failures (not-found,
validation, agent tool errors), Error on caught exceptions. Serilog
wraps the exception handler so request-completion logs report the
resolved status code rather than the raw exception. Never logs prose
bodies or the Anthropic API key.
This commit is contained in:
James Wampler
2026-08-06 12:11:20 -07:00
parent 4f396bb5f9
commit 04917fa09e
34 changed files with 790 additions and 147 deletions
@@ -0,0 +1,24 @@
namespace Novelly.Api.Common;
/// <summary>
/// Logs every request an endpoint group handles: Information on entry with the route's
/// name and values, Debug on exit with the resulting status. Applied per <c>MapGroup</c>
/// rather than inside each handler, so no endpoint lambda needs to know about logging.
/// </summary>
public class RequestLoggingEndpointFilter(ILogger<RequestLoggingEndpointFilter> logger) : IEndpointFilter
{
public async ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next)
{
var routeName = context.HttpContext.GetEndpoint()?.DisplayName ?? context.HttpContext.Request.Path;
logger.LogInformation(
"HTTP {Method} {Route} invoked with {@RouteValues}",
context.HttpContext.Request.Method, routeName, context.HttpContext.Request.RouteValues);
var result = await next(context);
logger.LogDebug("HTTP {Method} {Route} completed with {ResultType}", context.HttpContext.Request.Method, routeName, result?.GetType().Name);
return result;
}
}