From 3f3c5a96e01e5285c403376bad951af841481948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sam=20Geren=C3=A9?= Date: Mon, 16 Feb 2026 17:04:17 +0100 Subject: [PATCH] Configure Viewer Serilog from appsettings with console and file sinks --- SysML2.NET.Viewer/Program.cs | 25 +++++++-------- SysML2.NET.Viewer/SysML2.NET.Viewer.csproj | 14 +++++--- SysML2.NET.Viewer/wwwroot/appsettings.json | 37 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 SysML2.NET.Viewer/wwwroot/appsettings.json diff --git a/SysML2.NET.Viewer/Program.cs b/SysML2.NET.Viewer/Program.cs index 67603a2d2..cef377503 100644 --- a/SysML2.NET.Viewer/Program.cs +++ b/SysML2.NET.Viewer/Program.cs @@ -35,8 +35,7 @@ namespace SysML2.NET.Viewer using Radzen; - using Serilog; - using Serilog.Events; + using Serilog; using SySML2.NET.REST; using SysML2.NET.Serializer.Json; @@ -55,18 +54,16 @@ public static class Program /// /// an awaitable /// - public static async Task Main(string[] args) - { - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Debug() - .MinimumLevel.Override("Microsoft", LogEventLevel.Information) - .Enrich.FromLogContext() - .WriteTo.BrowserConsole() - .CreateLogger(); - - var builder = WebAssemblyHostBuilder.CreateDefault(args); - builder.Services.AddLogging(loggingBuilder => - loggingBuilder.AddSerilog(dispose: true)); + public static async Task Main(string[] args) + { + var builder = WebAssemblyHostBuilder.CreateDefault(args); + + Log.Logger = new LoggerConfiguration() + .ReadFrom.Configuration(builder.Configuration) + .CreateLogger(); + + builder.Services.AddLogging(loggingBuilder => + loggingBuilder.AddSerilog(dispose: true)); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); diff --git a/SysML2.NET.Viewer/SysML2.NET.Viewer.csproj b/SysML2.NET.Viewer/SysML2.NET.Viewer.csproj index 2cf6b3538..d4cb214b4 100644 --- a/SysML2.NET.Viewer/SysML2.NET.Viewer.csproj +++ b/SysML2.NET.Viewer/SysML2.NET.Viewer.csproj @@ -23,10 +23,16 @@ - - - - + + + + + + + + + + diff --git a/SysML2.NET.Viewer/wwwroot/appsettings.json b/SysML2.NET.Viewer/wwwroot/appsettings.json new file mode 100644 index 000000000..a36e13a36 --- /dev/null +++ b/SysML2.NET.Viewer/wwwroot/appsettings.json @@ -0,0 +1,37 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.Async" ], + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft": "Warning", + "System": "Warning" + } + }, + "WriteTo": [ + { + "Name": "Console" + }, + { + "Name": "Async", + "Args": { + "configure": [ + { + "Name": "File", + "Args": { + "path": "logs/log-reqifviewer-.txt", + "rollingInterval": "Day", + "rollOnFileSizeLimit": true + } + } + ] + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithProcessId", "WithThreadId" ], + "Properties": { + "Application": "dmap-cdao", + "Environment": "Production" + } + } +}