[CHANGE] Update logging config

This commit is contained in:
max
2025-08-04 20:15:03 +02:00
parent 18077ca58c
commit 3649d4fad4
2 changed files with 11 additions and 10 deletions

View File

@@ -14,7 +14,8 @@ public static class DependencyInjection
public static void SetupLogging(this WebApplicationBuilder builder) public static void SetupLogging(this WebApplicationBuilder builder)
{ {
var logSeverity = builder.Environment.IsDevelopment() ? LogSeverity.Debug : LogSeverity.Info; var isDevelopment = builder.Environment.IsDevelopment();
var logSeverity = isDevelopment ? LogSeverity.Debug : LogSeverity.Info;
var severityFilters = new Dictionary<string, LogSeverity>(); var severityFilters = new Dictionary<string, LogSeverity>();
var dotBasedLogSection = builder.Configuration.GetSection("DotBased:Logging"); var dotBasedLogSection = builder.Configuration.GetSection("DotBased:Logging");
@@ -39,8 +40,8 @@ public static class DependencyInjection
Log.Logger = new LoggerConfiguration().UseBasedExtension() Log.Logger = new LoggerConfiguration().UseBasedExtension()
.MinimumLevel.Verbose() .MinimumLevel.Verbose()
.Enrich.WithProperty("Application", "ImportUI") .Enrich.WithProperty("Application", "ImportUI")
.WriteTo.Console() .WriteTo.Console(outputTemplate: BasedSerilog.OutputTemplate)
.WriteTo.File(path: Path.Combine("Logs", $"{(builder.Environment.IsDevelopment() ? "Debug" : "Release")}", "log_.log"), rollingInterval: RollingInterval.Day, outputTemplate: BasedSerilog.OutputTemplate) .WriteTo.File(path: Path.Combine("Logs", $"{(isDevelopment ? "Debug" : "Release")}", "log_.log"), rollingInterval: RollingInterval.Day, outputTemplate: BasedSerilog.OutputTemplate)
.Destructure.ToMaximumDepth(4) .Destructure.ToMaximumDepth(4)
.Destructure.ToMaximumStringLength(100) .Destructure.ToMaximumStringLength(100)
.Destructure.ToMaximumCollectionCount(10).CreateLogger(); .Destructure.ToMaximumCollectionCount(10).CreateLogger();
@@ -48,7 +49,7 @@ public static class DependencyInjection
LogService.AddLogAdapter(new BasedSerilogAdapter(Log.Logger)); LogService.AddLogAdapter(new BasedSerilogAdapter(Log.Logger));
builder.Logging.ClearProviders(); builder.Logging.ClearProviders();
builder.Logging.SetMinimumLevel(LogLevel.Trace); builder.Logging.SetMinimumLevel(isDevelopment ? LogLevel.Trace : LogLevel.Information);
builder.Logging.AddDotBasedLoggerProvider(LogService.Options); builder.Logging.AddDotBasedLoggerProvider(LogService.Options);
} }
} }

View File

@@ -3,18 +3,18 @@
"Logging": { "Logging": {
"Severity": "Debug", "Severity": "Debug",
"SeverityFilters":{ "SeverityFilters":{
"Microsoft": "Info", "Microsoft": "Debug",
"Microsoft.Hosting.Lifetime": "Info", "Microsoft.Hosting.Lifetime": "Debug",
"Microsoft.AspNetCore": "Warning", "Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.Authentication": "Info", "Microsoft.AspNetCore.Authentication": "Debug",
"MudBlazor": "Info" "MudBlazor": "Debug"
} }
} }
}, },
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Trace",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Debug"
} }
} }
} }