From ae3c1aeb2a03a91df574d9bf1c4a5bead778f40e Mon Sep 17 00:00:00 2001 From: Ionite Date: Thu, 25 May 2023 21:05:33 -0400 Subject: [PATCH] Fix nlog --- StabilityMatrix/App.xaml.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/StabilityMatrix/App.xaml.cs b/StabilityMatrix/App.xaml.cs index 11d3f816..99a39d9b 100644 --- a/StabilityMatrix/App.xaml.cs +++ b/StabilityMatrix/App.xaml.cs @@ -1,4 +1,6 @@ -using System.Windows; +using System; +using System.IO; +using System.Windows; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; @@ -9,6 +11,7 @@ using StabilityMatrix.Services; using StabilityMatrix.ViewModels; using Wpf.Ui.Contracts; using Wpf.Ui.Services; +using SetupBuilderExtensions = NLog.SetupBuilderExtensions; namespace StabilityMatrix { @@ -29,14 +32,21 @@ namespace StabilityMatrix serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddRefitClient(); + + var logPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt"); + var logConfig = new NLog.Config.LoggingConfiguration(); + var fileTarget = new NLog.Targets.FileTarget("logfile") {FileName = logPath}; + logConfig.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, fileTarget); + NLog.LogManager.Configuration = logConfig; serviceCollection.AddLogging(log => { log.ClearProviders(); log.SetMinimumLevel(LogLevel.Trace); - log.AddNLog(); + log.AddNLog(logConfig); }); var provider = serviceCollection.BuildServiceProvider();