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.

52 lines
1.6 KiB

3 years ago
3 years ago
3 years ago
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", LogEventLevel.Information, rollingInterval: RollingInterval.Day))
  23. .WriteTo.Async(c => c.File("Logs/error.txt", LogEventLevel.Error, rollingInterval: RollingInterval.Day))
  24. .WriteTo.Async(c => c.Console())
  25. .CreateLogger();
  26. try
  27. {
  28. Log.Information("Starting Shentun.Peis.HttpApi.Host.");
  29. var builder = WebApplication.CreateBuilder(args);
  30. builder.Host.AddAppSettingsSecretsJson()
  31. .UseAutofac()
  32. .UseSerilog();
  33. await builder.AddApplicationAsync<PeisHttpApiHostModule>();
  34. var app = builder.Build();
  35. await app.InitializeApplicationAsync();
  36. await app.RunAsync();
  37. return 0;
  38. }
  39. catch (Exception ex)
  40. {
  41. Log.Fatal(ex, "Host terminated unexpectedly!");
  42. return 1;
  43. }
  44. finally
  45. {
  46. Log.CloseAndFlush();
  47. }
  48. }
  49. }