using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Builder;
namespace Admin.Core.RealTimeService
{
public class MainService
{
private string[] args;
public MainService(string[] vs)
{
CreateHostBuilder(args)
//生成宿主。
.Build()
// ※※※※ 有异常,查看 Log 文件夹下的异常日志 ※※※※
.RunAsync();
}
public void Start()
{
}
public void Stop()
{
}
///
/// CreateHostBuilder
///
///
///
public static IHostBuilder CreateHostBuilder(string[] args)
{
//初始化默认主机Builder
var hostBuilder = Host.CreateDefaultBuilder(args)
//Autofac服务工厂
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
})
.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;
}
}
}