feat(configmanager): add Serilog file logging to UI and create README

Configure Serilog for the ConfigManager UI application, replacing console
logging with daily rolling file logs in logs/ directory with 30-day
retention. Add shutdown handler to flush logs on exit.
This commit is contained in:
Joseph Doherty
2026-01-28 16:13:16 -05:00
parent 45f4ecab7d
commit f67b0e806e
2 changed files with 86 additions and 4 deletions
@@ -7,7 +7,8 @@ using JdeScoping.ConfigManager.Core.DependencyInjection;
using JdeScoping.ConfigManager.Ui.Services;
using JdeScoping.ConfigManager.Ui.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
namespace JdeScoping.ConfigManager.Ui;
@@ -37,6 +38,9 @@ public partial class App : Avalonia.Application
{
DataContext = Services.GetRequiredService<MainWindowViewModel>()
};
// Ensure logs are flushed on exit
desktop.ShutdownRequested += (_, _) => Log.CloseAndFlush();
}
base.OnFrameworkInitializationCompleted();
@@ -44,10 +48,24 @@ public partial class App : Avalonia.Application
private void ConfigureServices(IServiceCollection services)
{
// Configure Serilog with daily rolling file
var logsPath = Path.Combine(AppContext.BaseDirectory, "logs");
Directory.CreateDirectory(logsPath);
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Avalonia", LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.File(
path: Path.Combine(logsPath, "configmanager-.log"),
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 30,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.CreateLogger();
// Logging
services.AddLogging(builder => builder
.AddConsole()
.SetMinimumLevel(LogLevel.Debug));
services.AddLogging(builder => builder.AddSerilog(dispose: true));
// Add all ConfigManager.Core services
services.AddConfigManagerCore();