From 821f53b97acdc3da43b3c3c374374597c48377a7 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 5 Jan 2023 15:44:26 +0100 Subject: [PATCH] Simplify logging. --- .../Squidex/Config/Domain/LoggingServices.cs | 62 ++----------------- backend/src/Squidex/appsettings.json | 15 ++++- 2 files changed, 18 insertions(+), 59 deletions(-) diff --git a/backend/src/Squidex/Config/Domain/LoggingServices.cs b/backend/src/Squidex/Config/Domain/LoggingServices.cs index 78bb830c3..457e2b8da 100644 --- a/backend/src/Squidex/Config/Domain/LoggingServices.cs +++ b/backend/src/Squidex/Config/Domain/LoggingServices.cs @@ -18,72 +18,18 @@ public static class LoggingServices public static void ConfigureForSquidex(this ILoggingBuilder builder, IConfiguration config) { builder.ClearProviders(); - - // Also adds semantic logging. builder.ConfigureSemanticLog(config); - builder.AddConfiguration(config.GetSection("logging")); - builder.AddFilters(); - - builder.Services.AddServices(config); - } - - private static void AddServices(this IServiceCollection services, IConfiguration config) - { - services.Configure(config, + builder.Services.Configure(config, "logging"); - services.Configure(config, + builder.Services.Configure(config, "logging"); - services.AddSingletonAs(_ => new ApplicationInfoLogAppender(typeof(LoggingServices).Assembly, Guid.NewGuid())) + builder.Services.AddSingletonAs(_ => new ApplicationInfoLogAppender(typeof(LoggingServices).Assembly, Guid.NewGuid())) .As(); - services.AddSingletonAs() + builder.Services.AddSingletonAs() .As(); } - - private static void AddFilters(this ILoggingBuilder builder) - { - builder.AddFilter((category, level) => - { -#if LOG_ALL_IDENTITY_SERVER - if (category.StartsWith("Microsoft.AspNetCore.", StringComparison.OrdinalIgnoreCase)) - { - return true; - } - - if (category.StartsWith("IdentityServer4.", StringComparison.OrdinalIgnoreCase)) - { - return true; - } -#endif - if (level < LogLevel.Information) - { - return false; - } - - if (category == null) - { - return true; - } - - if (category.StartsWith("OpenIddict", StringComparison.OrdinalIgnoreCase)) - { - return level >= LogLevel.Warning; - } - - if (category.StartsWith("Runtime.", StringComparison.OrdinalIgnoreCase)) - { - return level >= LogLevel.Warning; - } - - if (category.StartsWith("Microsoft.AspNetCore.", StringComparison.OrdinalIgnoreCase)) - { - return level >= LogLevel.Warning; - } - - return true; - }); - } } diff --git a/backend/src/Squidex/appsettings.json b/backend/src/Squidex/appsettings.json index 0c9ab7f87..8966f63a5 100644 --- a/backend/src/Squidex/appsettings.json +++ b/backend/src/Squidex/appsettings.json @@ -307,11 +307,24 @@ }, "logging": { - // The log level. + // The log level of the implementation adapter. // // Trace, Debug, Information, Warning, Error, Fatal "level": "Information", + // The log level of the default log adapter. + "logLevel": { + "Default": "Information", + + // Only logs issued tokens. + "OpenIddict": "Warning", + + // Only logs request infos. + "Microsoft.AspNetCore": "Warning", + "Microsoft.Identity": "Warning", + "Runtime": "Warning" + }, + // Setting the flag to true, enables well formatteds json logs. "human": true,