You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using Admin.Core.Wpf.View;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using System;
|
|
using System.Windows;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.IO;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.Text;
|
|
using Autofac.Extensions.DependencyInjection;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Admin.Core.IService.ISys;
|
|
using Admin.Core.Tasks;
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
namespace Admin.Core.Wpf
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for App.xaml
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
public static IServiceProvider ServiceProvider;
|
|
|
|
protected override async void OnStartup(StartupEventArgs e)
|
|
{
|
|
base.OnStartup(e);
|
|
var host = CreateHostBuilder(e.Args).Build();//生成宿主。
|
|
|
|
ServiceProvider = host.Services;
|
|
host.Services.GetRequiredService<MainWindow>()?.Show();
|
|
await host.StartAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// CreateHostBuilder
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
public static IHostBuilder CreateHostBuilder(string[] args)
|
|
{
|
|
//初始化默认主机Builder
|
|
var hostBuilder = Host.CreateDefaultBuilder(args)
|
|
//Autofac服务工厂
|
|
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
webBuilder.UseStartup<Startup>();
|
|
})
|
|
.ConfigureLogging((hostingContext, builder) =>
|
|
{
|
|
//清楚控制台log日志
|
|
builder.ClearProviders();
|
|
// 1.过滤掉系统默认的一些日志
|
|
builder.AddFilter("System", LogLevel.Error);
|
|
builder.AddFilter("Microsoft", LogLevel.Error);
|
|
|
|
// 默认log4net.confg
|
|
builder.AddLog4Net(Path.Combine(Directory.GetCurrentDirectory(), "Log4net.config"));
|
|
});
|
|
|
|
return hostBuilder;
|
|
}
|
|
|
|
}
|
|
}
|