diff --git a/Webzine.WebApplication/Middlewares/LogTempsExecutionMiddleware.cs b/Webzine.WebApplication/Middlewares/LogTempsExecutionMiddleware.cs
index f871044..7a6e64a 100644
--- a/Webzine.WebApplication/Middlewares/LogTempsExecutionMiddleware.cs
+++ b/Webzine.WebApplication/Middlewares/LogTempsExecutionMiddleware.cs
@@ -19,21 +19,45 @@
}
// méthode appelée à chaque requête HTTP
+
+ ///
+ /// Middleware qui log pour suivre la vie d'une requete.
+ ///
+ ///
+ /// A representing the asynchronous operation.
public async Task InvokeAsync(HttpContext context)
{
// (Avant le contrôleur)
var chronometre = Stopwatch.StartNew(); // lance le chrono
- // C'est ici que le reste de l'application s'exécute (autres middlewares et Contrôleur)
+ // --- IN ---
+ var methode = context.Request.Method;
+ var endpoint = context.Request.Path;
+ var traceId = context.TraceIdentifier; // Identifiant unique généré par .NET
+
+ this.logger.LogInformation($"[IN] TraceId: {traceId} | Méthode: {methode} | Endpoint: {endpoint}");
+
await this.next(context);
// (Après le contrôleur)
chronometre.Stop(); // arrête le chrono
var tempsEcoule = chronometre.ElapsedMilliseconds;
- // écrit dans les logs l'URL de la page et le temps qu'elle a pris
- var urlPage = context.Request.Path;
- this.logger.LogInformation($"[MIDDLEWARE] La page {urlPage} a mis {tempsEcoule} ms à charger.");
+ 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}");
+ }
+ else if (httpCode >= 400)
+ {
+ this.logger.LogWarning($"[OUT] TraceId: {traceId} | HTTP {httpCode} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}");
+ }
+ else
+ {
+ this.logger.LogInformation($"[OUT] TraceId: {traceId} | HTTP {httpCode} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}");
+ }
}
}
}
\ No newline at end of file