diff --git a/Webzine.WebApplication/Middlewares/LogTempsExecutionMiddleware.cs b/Webzine.WebApplication/Middlewares/LogTempsExecutionMiddleware.cs index 6412b00..e6845fc 100644 --- a/Webzine.WebApplication/Middlewares/LogTempsExecutionMiddleware.cs +++ b/Webzine.WebApplication/Middlewares/LogTempsExecutionMiddleware.cs @@ -34,6 +34,7 @@ var methode = context.Request.Method; var endpoint = context.Request.Path; var traceId = context.TraceIdentifier; // Identifiant unique généré par .NET + var exceptionLevee = false; this.logger.LogInformation("[IN] TraceId: {traceId} | Méthode: {methode} | Endpoint: {endpoint}", traceId, methode, endpoint); @@ -43,13 +44,16 @@ } catch (Exception exception) { + exceptionLevee = true; chronometre.Stop(); this.logger.LogError( exception, - "[EXCEPTION] TraceId: {traceId} | Temps: {tempsEcoule} ms | Endpoint: {endpoint}", + "[EXCEPTION] TraceId: {traceId} | Temps: {tempsEcoule} ms | Endpoint: {endpoint} | Type: {exceptionType} | Message: {exceptionMessage}", traceId, chronometre.ElapsedMilliseconds, - endpoint); + endpoint, + exception.GetType().FullName, + exception.Message); throw; } finally @@ -60,7 +64,7 @@ } var tempsEcoule = chronometre.ElapsedMilliseconds; - var httpCode = context.Response.StatusCode; // exemple: 200, 404, 500 + var httpCode = exceptionLevee ? StatusCodes.Status500InternalServerError : context.Response.StatusCode; // exemple: 200, 404, 500 // --- OUT --- if (httpCode >= 500) diff --git a/Webzine.WebApplication/nlog.config b/Webzine.WebApplication/nlog.config index 2ff20bb..6a90a9a 100644 --- a/Webzine.WebApplication/nlog.config +++ b/Webzine.WebApplication/nlog.config @@ -23,7 +23,7 @@ + layout="${longdate}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}" /> @@ -32,10 +32,10 @@ - + - \ No newline at end of file +