From 73142d7dde2d8968453de738cc389d24de11dc9b Mon Sep 17 00:00:00 2001 From: Nate Bross Date: Tue, 10 Oct 2023 21:44:32 -0500 Subject: [PATCH] chore: split log targets by source and level, include started and shutdown log events, add log file rotation. (#20) - Write all logs to console target - Write Info logs to logfile target except: - Avalonia.* only log Warning and above. - Move log folder to AppData\SharpFM\Application.log. - Rotate logs every 30 days. --- SharpFM.App/Program.cs | 10 ++++++++++ SharpFM.App/nlog.config | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/SharpFM.App/Program.cs b/SharpFM.App/Program.cs index 8c3952a..6c63ec9 100644 --- a/SharpFM.App/Program.cs +++ b/SharpFM.App/Program.cs @@ -1,4 +1,5 @@ using Avalonia; +using NLog; using System; namespace SharpFM.App; @@ -11,7 +12,16 @@ class Program [STAThread] public static void Main(string[] args) { + var logger = LogManager + .Setup() + .LoadConfigurationFromFile("nlog.config") + .GetCurrentClassLogger(); + + logger.Info("SharpFM has started up."); + BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); + + logger.Info("SharpFM has shut down."); } // Avalonia configuration, don't remove; also used by visual designer. diff --git a/SharpFM.App/nlog.config b/SharpFM.App/nlog.config index dc6ab63..a9fc30d 100644 --- a/SharpFM.App/nlog.config +++ b/SharpFM.App/nlog.config @@ -23,12 +23,25 @@ - + + + + + + + + \ No newline at end of file