diff --git a/CHANGELOG.md b/CHANGELOG.md index e4c5251f..3ed3f643 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Prefix your items with `(Template)` if the change is about the template and not ## 3.4.X - Added a kill switch feature to the app. - Bump Uno.WinUI, Uno.WinUI.DevServer, Uno.WinUI.Lottie and Uno.UI.Adapter.Microsoft.Extensions.Logging to 5.0.159 to fix backNavigation/CloseModal crash. +- Fixed an issue with logging configuration not creating the directory before writing the log file in the case logging was disabled by default. ## 3.3.X - Added a forced update feature to the app. diff --git a/src/app/ApplicationTemplate.Shared.Views/Configuration/LoggingConfiguration.cs b/src/app/ApplicationTemplate.Shared.Views/Configuration/LoggingConfiguration.cs index ab3d9b32..3e2daf01 100644 --- a/src/app/ApplicationTemplate.Shared.Views/Configuration/LoggingConfiguration.cs +++ b/src/app/ApplicationTemplate.Shared.Views/Configuration/LoggingConfiguration.cs @@ -37,9 +37,17 @@ public static void ConfigureLogging(HostBuilderContext hostBuilderContext, ILogg AddConsoleLogging(serilogConfiguration); } + var filepath = logFilesProvider.GetLogFilePath(isAppLogging); + if (options.IsFileLoggingEnabled) { - AddFileLogging(serilogConfiguration, logFilesProvider.GetLogFilePath(isAppLogging)); + AddFileLogging(serilogConfiguration, filepath); + } + else + { + // Ensures the directory is created so we can still write on files down the line. + var directoryPath = Path.GetDirectoryName(filepath); + Directory.CreateDirectory(directoryPath); } var logger = serilogConfiguration.CreateLogger();