Browse Source

Simplify logging.

pull/965/head
Sebastian 3 years ago
parent
commit
821f53b97a
  1. 62
      backend/src/Squidex/Config/Domain/LoggingServices.cs
  2. 15
      backend/src/Squidex/appsettings.json

62
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<RequestLogOptions>(config,
builder.Services.Configure<RequestLogOptions>(config,
"logging");
services.Configure<RequestLogStoreOptions>(config,
builder.Services.Configure<RequestLogStoreOptions>(config,
"logging");
services.AddSingletonAs(_ => new ApplicationInfoLogAppender(typeof(LoggingServices).Assembly, Guid.NewGuid()))
builder.Services.AddSingletonAs(_ => new ApplicationInfoLogAppender(typeof(LoggingServices).Assembly, Guid.NewGuid()))
.As<ILogAppender>();
services.AddSingletonAs<ActionContextLogAppender>()
builder.Services.AddSingletonAs<ActionContextLogAppender>()
.As<ILogAppender>();
}
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;
});
}
}

15
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,

Loading…
Cancel
Save