#1 : Gougougaga.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user