From 05657d77ba1ea53ef3a772a4bf78f93bb6d9e89d Mon Sep 17 00:00:00 2001 From: liuwf Date: Wed, 30 Oct 2024 17:16:28 +0800 Subject: [PATCH] =?UTF-8?q?change-=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=8F=8A=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Serilog/SerilogExtensions.cs | 6 +++++- SlnMesnac.WPF/SlnMesnac.WPF.csproj | 2 +- SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/SlnMesnac.Serilog/SerilogExtensions.cs b/SlnMesnac.Serilog/SerilogExtensions.cs index 6f9b303..f9e5128 100644 --- a/SlnMesnac.Serilog/SerilogExtensions.cs +++ b/SlnMesnac.Serilog/SerilogExtensions.cs @@ -37,12 +37,16 @@ namespace SlnMesnac.Serilog { public static IApplicationBuilder UseSerilogExtensions(this IApplicationBuilder app) { + // 获取当前程序所在的目录 + string currentDirectory = Directory.GetCurrentDirectory(); + //启用Serilog中间件 app.UseSerilogRequestLogging(); #region 通过配置文件读取日志存放位置 var appConfig = app.ApplicationServices.GetService(); - var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; + // var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; + var logPath = $"{currentDirectory}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; #endregion Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console() diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj index 4ec2f07..ffca841 100644 --- a/SlnMesnac.WPF/SlnMesnac.WPF.csproj +++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj @@ -1,7 +1,7 @@  - Exe + WinExe net6.0-windows enable true diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index 11a4e5f..362fa60 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -327,8 +327,12 @@ namespace SlnMesnac.WPF.ViewModel PageName = "生产统计"; break; case "Exit":// 关闭当前窗口 - //Environment.Exit(0); - Application.Current.Shutdown(); + var result = MessageBox.Show("确定要关闭程序吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions.None); + if (result== MessageBoxResult.Yes) + { + _logger.LogWarning("用户手动关闭程序"); + Application.Current.Shutdown(); + } break; case "Generate": UserContent = generateControl;