Skip to content

Commit

Permalink
Fixes Log client ID (and engine ID if appropriate) when returning 400…
Browse files Browse the repository at this point in the history
… or 500 codes #103 --ECL
  • Loading branch information
Enkidu93 committed Sep 12, 2023
1 parent 1ed350f commit e43b176
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Serval.Shared/Controllers/ErrorResultFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Text.Json;

namespace Serval.Shared.Controllers
{
Expand All @@ -15,7 +16,9 @@ public override Task OnResultExecutionAsync(ResultExecutingContext context, Resu
{
if ((context.Result is ObjectResult r) && (r.StatusCode >= 400))
{
_logger.LogInformation($"Responded with code {r.StatusCode}. Trace: {Activity.Current?.Id}");
_logger.LogInformation(
$"Client {((Controller)context.Controller).User.Identity?.Name?.ToString()} made request:\n {JsonSerializer.Serialize(((Controller)context.Controller).ControllerContext.RouteData.Values, new JsonSerializerOptions { WriteIndented = true })}.\n Serval responded with code {r.StatusCode}. Trace: {Activity.Current?.Id}"
);
}
return base.OnResultExecutionAsync(context, next);
}
Expand Down

0 comments on commit e43b176

Please sign in to comment.