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.
62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
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()
|
|
{
|
|
}
|
|
|
|
/// <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;
|
|
}
|
|
}
|
|
}
|