diff --git a/ImportUI/Components/App.razor b/ImportUI/Components/App.razor index 7aa9339..6dfe981 100644 --- a/ImportUI/Components/App.razor +++ b/ImportUI/Components/App.razor @@ -7,7 +7,6 @@ - diff --git a/ImportUI/DependencyInjection.cs b/ImportUI/DependencyInjection.cs new file mode 100644 index 0000000..ee87424 --- /dev/null +++ b/ImportUI/DependencyInjection.cs @@ -0,0 +1,54 @@ +using DotBased.Logging; +using DotBased.Logging.MEL; +using DotBased.Logging.Serilog; +using Serilog; + +namespace ImportUI; + +public static class DependencyInjection +{ + public static WebApplicationBuilder InjectDependencies(this WebApplicationBuilder builder) + { + return builder; + } + + public static void SetupLogging(this WebApplicationBuilder builder) + { + var logSeverity = builder.Environment.IsDevelopment() ? LogSeverity.Debug : LogSeverity.Info; + var severityFilters = new Dictionary(); + + var dotBasedLogSection = builder.Configuration.GetSection("DotBased:Logging"); + if (dotBasedLogSection.Exists()) + { + logSeverity = dotBasedLogSection.GetValue("Severity"); + severityFilters = dotBasedLogSection.GetSection("SeverityFilters").GetChildren() + .ToDictionary( + x => x.Key, + x => x.Get() + ); + } + + LogService.Initialize(options => + { + options.Severity = logSeverity; + foreach (var filter in severityFilters) + { + options.AddSeverityFilter(filter.Key, filter.Value); + } + }); + Log.Logger = new LoggerConfiguration().UseBasedExtension() + .MinimumLevel.Verbose() + .Enrich.WithProperty("Application", "ImportUI") + .WriteTo.Console() + .WriteTo.File(path: Path.Combine("Logs", $"{(builder.Environment.IsDevelopment() ? "Debug" : "Release")}", "log_.log"), rollingInterval: RollingInterval.Day, outputTemplate: BasedSerilog.OutputTemplate) + .Destructure.ToMaximumDepth(4) + .Destructure.ToMaximumStringLength(100) + .Destructure.ToMaximumCollectionCount(10).CreateLogger(); + + LogService.AddLogAdapter(new BasedSerilogAdapter(Log.Logger)); + + builder.Logging.ClearProviders(); + builder.Logging.SetMinimumLevel(LogLevel.Trace); + builder.Logging.AddDotBasedLoggerProvider(LogService.Options); + } +} \ No newline at end of file diff --git a/ImportUI/ImportUI.csproj b/ImportUI/ImportUI.csproj index 8151880..17162c2 100644 --- a/ImportUI/ImportUI.csproj +++ b/ImportUI/ImportUI.csproj @@ -11,6 +11,8 @@ + + diff --git a/ImportUI/Program.cs b/ImportUI/Program.cs index 508b6cb..729291e 100644 --- a/ImportUI/Program.cs +++ b/ImportUI/Program.cs @@ -1,3 +1,4 @@ +using ImportUI; using ImportUI.Components; using MudBlazor.Services; @@ -7,6 +8,8 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); +builder.SetupLogging(); + /* MudBlazor */ builder.Services.AddMudServices(); diff --git a/ImportUI/appsettings.Development.json b/ImportUI/appsettings.Development.json index 0c208ae..f8a136c 100644 --- a/ImportUI/appsettings.Development.json +++ b/ImportUI/appsettings.Development.json @@ -1,4 +1,16 @@ { + "DotBased": { + "Logging": { + "Severity": "Debug", + "SeverityFilters":{ + "Microsoft": "Info", + "Microsoft.Hosting.Lifetime": "Info", + "Microsoft.AspNetCore": "Warning", + "Microsoft.AspNetCore.Authentication": "Info", + "MudBlazor": "Info" + } + } + }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/ImportUI/appsettings.json b/ImportUI/appsettings.json index 10f68b8..b044c11 100644 --- a/ImportUI/appsettings.json +++ b/ImportUI/appsettings.json @@ -1,4 +1,16 @@ { + "DotBased": { + "Logging": { + "Severity": "Info", + "SeverityFilters":{ + "Microsoft": "Info", + "Microsoft.Hosting.Lifetime": "Info", + "Microsoft.AspNetCore": "Warning", + "Microsoft.AspNetCore.Authentication": "Info", + "MudBlazor": "Info" + } + } + }, "Logging": { "LogLevel": { "Default": "Information",