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.

103 lines
3.8KB

  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Serialization;
  3. using Serilog;
  4. using TelpoDataService.Util.Clients;
  5. using TelpoPush.Common;
  6. using TelpoPush.Models.Config;
  7. using TelpoPush.Service.Biz;
  8. using TelpoPush.Service.Cache;
  9. using TelpoPush.Service.Mq.Kafka;
  10. using TelpoPush.Worker.ThirdSsl;
  11. using TelpoPush.Worker.ThirdSsl.Handlers;
  12. #region 日志
  13. //using Serilog.Events;
  14. //using Serilog;
  15. //using Microsoft.AspNetCore.Builder;
  16. //Log.Logger = new LoggerConfiguration()
  17. //#if DEBUG
  18. // .MinimumLevel.Debug()
  19. //#else
  20. // .MinimumLevel.Information()
  21. //#endif
  22. // .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
  23. // .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
  24. // .Enrich.FromLogContext()
  25. // //.Filter.ByExcluding(c => c.Properties.Any(p => p.Value.ToString().Contains("Microsoft")))//过滤
  26. // .WriteTo.Async(c => c.File("/var/telpo_pushthird_ssl2/logs/infos/info.log",
  27. // restrictedToMinimumLevel: LogEventLevel.Information,
  28. // rollingInterval: RollingInterval.Day,//滚动策略(天)
  29. // //fileSizeLimitBytes: 20971520, //设置单个文件大小为3M 默认1G
  30. // rollOnFileSizeLimit: true, //超过文件大小后创建新的
  31. // retainedFileCountLimit: 7,//默认31,意思就是只保留最近的31个日志文件"
  32. // outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff}[{Level:u3}] [Thread-{ThreadId}] [{SourceContext:l}] {Message:lj}{NewLine}{Exception}"
  33. // )
  34. // )
  35. // .WriteTo.Async(c => c.File("/var/telpo_pushthird_ssl2/logs/errors/errors.log",
  36. // restrictedToMinimumLevel: LogEventLevel.Error,
  37. // rollingInterval: RollingInterval.Day,
  38. // rollOnFileSizeLimit: true,
  39. // retainedFileCountLimit: 7,
  40. // outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff }[{Level:u3}] [Thread-{ThreadId}] [{SourceContext:l}] {Message:lj}{NewLine}{Exception}"
  41. // )
  42. // )
  43. // .WriteTo.Async(c => c.Console())
  44. // .CreateLogger();
  45. //选择配置文件appsetting.json
  46. var configuration = new ConfigurationBuilder()
  47. .SetBasePath(Directory.GetCurrentDirectory())
  48. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  49. .Build();
  50. Log.Logger = new LoggerConfiguration()
  51. .ReadFrom.Configuration(configuration)
  52. .Enrich.WithThreadId()
  53. .CreateLogger();
  54. #endregion
  55. try
  56. {
  57. Log.Information("Starting up");
  58. var builder = Host.CreateApplicationBuilder(args);
  59. var config = builder.Configuration;
  60. builder.Services.Configure<ServiceConfig>(config.GetSection("ServiceConfig"));
  61. builder.Services.Configure<RedisConfig>(config.GetSection("Redis"));
  62. JsonSerializerSettings setting = new JsonSerializerSettings();
  63. JsonConvert.DefaultSettings = () =>
  64. {
  65. setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
  66. setting.ContractResolver = new CamelCasePropertyNamesContractResolver();
  67. return setting;
  68. };
  69. builder.Services.AddTelpoDataServices(opt =>
  70. {
  71. opt.TelpoDataUrl = config["ServiceConfig:TelpoDataUrl"];
  72. });
  73. builder.Services.AddSerilog();
  74. builder.Services.AddHttpClient();
  75. builder.Services.AddTransient<HttpHelperAsync>();
  76. builder.Services.AddSingleton<SqlMapper>();
  77. builder.Services.AddSingleton<RedisUtil>();
  78. builder.Services.AddSingleton<IZkRealHRMonitorService, ZkRealHRMonitorService>();
  79. builder.Services.AddSingleton<IKafkaService, KafkaService>();
  80. builder.Services.AddSingleton<KafkaSubscribe>();
  81. builder.Services.AddSingleton<MessageProducer>();
  82. builder.Services.AddSingleton<MqProcessMessage>();
  83. builder.Services.AddSingleton<ThirdSslProcess>();
  84. builder.Services.AddHostedService<Worker>();
  85. var host = builder.Build();
  86. host.Run();
  87. }
  88. catch (Exception ex)
  89. {
  90. Log.Fatal(ex, "Application start-up failed");
  91. }
  92. finally
  93. {
  94. Log.CloseAndFlush();
  95. }