1. public static IHostBuilder CreateHostBuilder(string[] args) =>
    2. Host.CreateDefaultBuilder(args)
    3. .UseServiceProviderFactory(new AutofacServiceProviderFactory())
    4. .ConfigureAppConfiguration((hostingContext, config) =>
    5. {
    6. #region Configuration
    7. config.AddJsonFile(ConfigFileHelper.GetFilePath("configs/ipratelimit.json", Environment.CurrentDirectory), optional: true, reloadOnChange: true);
    8. #endregion
    9. })
    10. .ConfigureWebHostDefaults(webBuilder =>
    11. {
    12. #region 加载启动文件
    13. var configuration = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory)
    14. .AddJsonFile(ConfigFileHelper.GetFilePath("configs/host.json", Environment.CurrentDirectory))
    15. .Build();
    16. #endregion
    17. #region 启动项
    18. webBuilder.UseStartup<Startup>()
    19. .UseUrls(configuration["urls"])
    20. .ConfigureAppConfiguration((hostingContext, config) =>
    21. {
    22. #region json 配置信息
    23. config.AddCommandLine(args);
    24. #endregion
    25. })
    26. .ConfigureLogging((hostingContext, builder) =>
    27. {
    28. #region 日志信息
    29. //clear all previously registered providers
    30. builder.ClearProviders();
    31. //过滤掉系统默认的一些日志
    32. builder.AddFilter("System", LogLevel.Error);
    33. builder.AddFilter("Microsoft", LogLevel.Error);
    34. builder.AddFilter("Microsoft.Hosting.Lifetime",LogLevel.Error);
    35. #region Log4Net配置文件
    36. Panda.Framework.Helper.ConsoleHelper.WriteSuccessLine($"start success:{ configuration["urls"] }");
    37. var file = Panda.Framework.Configs.ConfigFileHelper.GetFilePath(configuration["log4net"], AppDomain.CurrentDomain.BaseDirectory);
    38. if (!File.Exists(file))
    39. {
    40. file = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configuration["log4net"]);
    41. }
    42. builder.AddLog4Net(file);
    43. Panda.Framework.Helper.ConsoleHelper.WriteSuccessLine($"load log4net success:{file}");
    44. #endregion
    45. #endregion
    46. });
    47. #endregion
    48. });