[CHANGE] Added logging

This commit is contained in:
max
2025-08-04 19:36:12 +02:00
parent 0f8530b9c0
commit 18077ca58c
6 changed files with 83 additions and 1 deletions

View File

@@ -7,7 +7,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<base href="/"/>
<link rel="stylesheet" href="app.css"/>
<link rel="stylesheet" href="ImportUI.styles.css"/>
<link rel="icon" type="image/png" href="favicon.png"/>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet"/>
<link href="_content/MudBlazor/MudBlazor.min.css?v=@Metadata.Version" rel="stylesheet"/>

View File

@@ -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<string, LogSeverity>();
var dotBasedLogSection = builder.Configuration.GetSection("DotBased:Logging");
if (dotBasedLogSection.Exists())
{
logSeverity = dotBasedLogSection.GetValue<LogSeverity>("Severity");
severityFilters = dotBasedLogSection.GetSection("SeverityFilters").GetChildren()
.ToDictionary(
x => x.Key,
x => x.Get<LogSeverity>()
);
}
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);
}
}

View File

@@ -11,6 +11,8 @@
<PackageReference Include="DotBased.Logging.MEL" Version="1.0.0" />
<PackageReference Include="DotBased.Logging.Serilog" Version="1.0.0" />
<PackageReference Include="MudBlazor" Version="8.10.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -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();

View File

@@ -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",

View File

@@ -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",