public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureAppConfiguration((hostingContext, config) =>
{
#region Configuration
config.AddJsonFile(ConfigFileHelper.GetFilePath("configs/ipratelimit.json", Environment.CurrentDirectory), optional: true, reloadOnChange: true);
#endregion
})
.ConfigureWebHostDefaults(webBuilder =>
{
#region 加载启动文件
var configuration = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory)
.AddJsonFile(ConfigFileHelper.GetFilePath("configs/host.json", Environment.CurrentDirectory))
.Build();
#endregion
#region 启动项
webBuilder.UseStartup<Startup>()
.UseUrls(configuration["urls"])
.ConfigureAppConfiguration((hostingContext, config) =>
{
#region json 配置信息
config.AddCommandLine(args);
#endregion
})
.ConfigureLogging((hostingContext, builder) =>
{
#region 日志信息
//clear all previously registered providers
builder.ClearProviders();
//过滤掉系统默认的一些日志
builder.AddFilter("System", LogLevel.Error);
builder.AddFilter("Microsoft", LogLevel.Error);
builder.AddFilter("Microsoft.Hosting.Lifetime",LogLevel.Error);
#region Log4Net配置文件
Panda.Framework.Helper.ConsoleHelper.WriteSuccessLine($"start success:{ configuration["urls"] }");
var file = Panda.Framework.Configs.ConfigFileHelper.GetFilePath(configuration["log4net"], AppDomain.CurrentDomain.BaseDirectory);
if (!File.Exists(file))
{
file = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configuration["log4net"]);
}
builder.AddLog4Net(file);
Panda.Framework.Helper.ConsoleHelper.WriteSuccessLine($"load log4net success:{file}");
#endregion
#endregion
});
#endregion
});