临河任务调度
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.7KB

  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 Himp.TaskScheduling;
  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. rollingInterval: RollingInterval.Infinite,
  24. fileSizeLimitBytes: 1_000_000,
  25. rollOnFileSizeLimit: true))
  26. .WriteTo.Async(c => c.Console())
  27. .CreateLogger();
  28. try
  29. {
  30. Log.Information("Starting web host.");
  31. var builder = WebApplication.CreateBuilder(args);
  32. builder.Host.AddAppSettingsSecretsJson()
  33. .UseAutofac()
  34. .UseSerilog();
  35. await builder.AddApplicationAsync<TaskSchedulingHttpApiHostModule>();
  36. var app = builder.Build();
  37. await app.InitializeApplicationAsync();
  38. await app.RunAsync();
  39. return 0;
  40. }
  41. catch (Exception ex)
  42. {
  43. if (ex is HostAbortedException)
  44. {
  45. throw;
  46. }
  47. Log.Fatal(ex, "Host terminated unexpectedly!");
  48. return 1;
  49. }
  50. finally
  51. {
  52. Log.CloseAndFlush();
  53. }
  54. }
  55. }