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.

51 lines
1.5 KiB

3 years ago
  1. using System;
  2. using System.Threading.Tasks;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using Microsoft.Extensions.Hosting;
  6. using Serilog;
  7. using Serilog.Events;
  8. namespace Shentun.Peis;
  9. public class Program
  10. {
  11. public async static Task<int> Main(string[] args)
  12. {
  13. Log.Logger = new LoggerConfiguration()
  14. #if DEBUG
  15. .MinimumLevel.Debug()
  16. #else
  17. .MinimumLevel.Information()
  18. #endif
  19. .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
  20. .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
  21. .Enrich.FromLogContext()
  22. .WriteTo.Async(c => c.File("Logs/logs.txt"))
  23. .WriteTo.Async(c => c.Console())
  24. .CreateLogger();
  25. try
  26. {
  27. Log.Information("Starting Shentun.Peis.HttpApi.Host.");
  28. var builder = WebApplication.CreateBuilder(args);
  29. builder.Host.AddAppSettingsSecretsJson()
  30. .UseAutofac()
  31. .UseSerilog();
  32. await builder.AddApplicationAsync<PeisHttpApiHostModule>();
  33. var app = builder.Build();
  34. await app.InitializeApplicationAsync();
  35. await app.RunAsync();
  36. return 0;
  37. }
  38. catch (Exception ex)
  39. {
  40. Log.Fatal(ex, "Host terminated unexpectedly!");
  41. return 1;
  42. }
  43. finally
  44. {
  45. Log.CloseAndFlush();
  46. }
  47. }
  48. }