#1 : Gougougaga.

This commit is contained in:
Loic Masi
2026-04-21 11:55:31 +02:00
parent 3a116f9bae
commit 74ff359049
4 changed files with 55 additions and 17 deletions

View File

@@ -37,26 +37,44 @@
this.logger.LogInformation("[IN] TraceId: {traceId} | Méthode: {methode} | Endpoint: {endpoint}", traceId, methode, endpoint);
await this.next(context);
// (Après le contrôleur)
chronometre.Stop(); // arrête le chrono
var tempsEcoule = chronometre.ElapsedMilliseconds;
var httpCode = context.Response.StatusCode; // exemple: 200, 404, 500
// --- OUT ---
if (httpCode >= 500)
try
{
this.logger.LogError("[OUT] TraceId: {traceId} | HTTP {httpCode} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}", traceId, httpCode, tempsEcoule, endpoint);
await this.next(context);
}
else if (httpCode >= 400)
catch (Exception exception)
{
this.logger.LogWarning("[OUT] TraceId: {traceId} | HTTP {httpCode} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}", traceId, httpCode, tempsEcoule, endpoint);
chronometre.Stop();
this.logger.LogError(
exception,
"[EXCEPTION] TraceId: {traceId} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}",
traceId,
chronometre.ElapsedMilliseconds,
endpoint);
throw;
}
else
finally
{
this.logger.LogInformation("[OUT] TraceId: {traceId} | HTTP {httpCode} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}", traceId, httpCode, tempsEcoule, endpoint);
if (chronometre.IsRunning)
{
chronometre.Stop();
}
var tempsEcoule = chronometre.ElapsedMilliseconds;
var httpCode = context.Response.StatusCode; // exemple: 200, 404, 500
// --- OUT ---
if (httpCode >= 500)
{
this.logger.LogError("[OUT] TraceId: {traceId} | HTTP {httpCode} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}", traceId, httpCode, tempsEcoule, endpoint);
}
else if (httpCode >= 400)
{
this.logger.LogWarning("[OUT] TraceId: {traceId} | HTTP {httpCode} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}", traceId, httpCode, tempsEcoule, endpoint);
}
else
{
this.logger.LogInformation("[OUT] TraceId: {traceId} | HTTP {httpCode} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}", traceId, httpCode, tempsEcoule, endpoint);
}
}
}
}