using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog; using SlnMesnac.Config; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; namespace SlnMesnac.WPF { /// /// Interaction logic for App.xaml /// public partial class App : Application { public static IServiceProvider ServiceProvider; // Startup事件 protected override async void OnStartup(StartupEventArgs e) { base.OnStartup(e); var host = CreateHostBuilder(e.Args).Build();//生成宿主。 ServiceProvider = host.Services; await host.StartAsync(); var appConfig = host.Services.GetService(); var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}"); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); // Exit事件 protected override void OnExit(ExitEventArgs e) { base.OnExit(e); // 释放资源 // ... } } }