From 7436d1271ee734c9cc2013afc48847d4e2d4ddcc Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 17 Dec 2024 14:53:00 +0100 Subject: [PATCH] Added a filter to not log application exceptions. Unknown exceptions are still logged, so we can collect reports of these and eventually wrap them in user information exceptions. --- Duplicati/WebserverCore/DuplicatiWebserver.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Duplicati/WebserverCore/DuplicatiWebserver.cs b/Duplicati/WebserverCore/DuplicatiWebserver.cs index 1cc8e361b..884583e5e 100644 --- a/Duplicati/WebserverCore/DuplicatiWebserver.cs +++ b/Duplicati/WebserverCore/DuplicatiWebserver.cs @@ -218,7 +218,8 @@ public partial class DuplicatiWebserver .AddFilter("Microsoft", LogLevel.Warning) .AddFilter("Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager", LogLevel.Error) .AddFilter("System", LogLevel.Warning) - .AddFilter("Duplicati", LogLevel.Warning); + .AddFilter("Duplicati", LogLevel.Warning) + .AddFilter("Microsoft.AspNetCore.Diagnostics", LogLevel.None); } builder.Services.AddHttpClient(); @@ -260,6 +261,10 @@ public partial class DuplicatiWebserver } else { + // These are unexpected exceptions, so log them + app.ApplicationServices.GetRequiredService>() + .LogError(thrownException, "Unhandled exception"); + context.Response.StatusCode = 500; context.Response.ContentType = "application/json"; await context.Response.WriteAsync(JsonSerializer.Serialize(new { Error = "An error occurred", Code = 500 }));