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.

60 lines
1.9 KiB

2 years ago
4 months ago
3 years ago
3 years ago
4 months ago
3 years ago
4 months ago
4 months ago
2 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. using Shentun.Peis.Filter;
  9. namespace Shentun.Peis;
  10. public class Program
  11. {
  12. public async static Task<int> Main(string[] args)
  13. {
  14. try
  15. {
  16. var builder = WebApplication.CreateBuilder(args);
  17. var configuration = builder.Configuration;
  18. Log.Logger = new LoggerConfiguration()
  19. #if DEBUG
  20. .MinimumLevel.Debug()
  21. #else
  22. .MinimumLevel.Information()
  23. #endif
  24. .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
  25. .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
  26. .Enrich.FromLogContext()
  27. .Filter.With(new ExcludeHealthCheckFilter(configuration))
  28. .WriteTo.Async(c => c.File("Logs/logs.txt", LogEventLevel.Information, rollingInterval: RollingInterval.Day))
  29. .WriteTo.Async(c => c.File("Logs/error.txt", LogEventLevel.Error, rollingInterval: RollingInterval.Day))
  30. .WriteTo.Async(c => c.Console())
  31. .CreateLogger();
  32. Log.Information("Starting Shentun.Peis.HttpApi.Host.");
  33. builder.Host.AddAppSettingsSecretsJson()
  34. .UseAutofac()
  35. .UseSerilog();
  36. await builder.AddApplicationAsync<PeisHttpApiHostModule>();
  37. var app = builder.Build();
  38. await app.InitializeApplicationAsync();
  39. //GenerateCertificateHelper gc = new GenerateCertificateHelper();
  40. //gc.GenerateEncryptionCertificate();
  41. //gc.GenerateSigningCertificate();
  42. await app.RunAsync();
  43. return 0;
  44. }
  45. catch (Exception ex)
  46. {
  47. Log.Fatal(ex, "Host terminated unexpectedly!");
  48. return 1;
  49. }
  50. finally
  51. {
  52. Log.CloseAndFlush();
  53. }
  54. }
  55. }