change-优化日志及退出

dev
liuwf 2 weeks ago
parent d6f2f64a7c
commit 05657d77ba

@ -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<AppConfig>();
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()

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>

@ -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;

Loading…
Cancel
Save