You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using System;
  2. using System.Threading.Tasks;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Server.Kestrel.Core;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Hosting;
  8. using Serilog;
  9. using Serilog.Events;
  10. using Shentun.Utilities;
  11. namespace Shentun.WebPeis;
  12. public class Program
  13. {
  14. public async static Task<int> Main(string[] args)
  15. {
  16. var configuration = new ConfigurationBuilder()
  17. .SetBasePath(DirectoryHelper.GetAppDirectory())
  18. .AddJsonFile("Serilog.json", false, reloadOnChange: true)
  19. .Build();
  20. Log.Logger = new LoggerConfiguration()
  21. #if DEBUG
  22. .MinimumLevel.Debug()
  23. #else
  24. .MinimumLevel.Information()
  25. #endif
  26. //.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
  27. //.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
  28. //.Enrich.FromLogContext()
  29. //.WriteTo.Async(c => c.File("Logs/logs.txt"))
  30. //.WriteTo.Async(c => c.Console())
  31. .ReadFrom.Configuration(configuration)
  32. .CreateLogger();
  33. try
  34. {
  35. Log.Information("Starting Shentun.WebPeis.HttpApi.Host.");
  36. var builder = WebApplication.CreateBuilder(args);
  37. builder.Host.AddAppSettingsSecretsJson()
  38. .UseAutofac()
  39. .UseSerilog();
  40. await builder.AddApplicationAsync<WebPeisHttpApiHostModule>();
  41. var app = builder.Build();
  42. await app.InitializeApplicationAsync();
  43. await app.RunAsync();
  44. return 0;
  45. }
  46. catch (Exception ex)
  47. {
  48. if (ex is HostAbortedException)
  49. {
  50. throw;
  51. }
  52. Log.Fatal(ex, "Host terminated unexpectedly!");
  53. return 1;
  54. }
  55. finally
  56. {
  57. Log.CloseAndFlush();
  58. }
  59. }
  60. }