临河任务调度
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

57 行
1.6KB

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