电子围栏推送服务
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 5 Monaten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Serialization;
  3. using Serilog;
  4. using TelpoDataService.Util.Clients;
  5. using TelpoPush.Fence.Worker;
  6. using TelpoPush.Fence.Worker.Common;
  7. using TelpoPush.Fence.Worker.Handlers;
  8. using TelpoPush.Fence.Worker.Models.Config;
  9. using TelpoPush.Fence.Worker.Service.Cache;
  10. using TelpoPush.Fence.Worker.Service.Mq;
  11. try
  12. {
  13. #region ־
  14. //using Serilog.Events;
  15. //using Serilog;
  16. //using Microsoft.AspNetCore.Builder;
  17. //Log.Logger = new LoggerConfiguration()
  18. //#if DEBUG
  19. // .MinimumLevel.Debug()
  20. //#else
  21. // .MinimumLevel.Information()
  22. //#endif
  23. // .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
  24. // .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
  25. // .Enrich.FromLogContext()
  26. // //.Filter.ByExcluding(c => c.Properties.Any(p => p.Value.ToString().Contains("Microsoft")))//
  27. // .WriteTo.Async(c => c.File("/var/telpo_pushthird_ssl2/logs/infos/info.log",
  28. // restrictedToMinimumLevel: LogEventLevel.Information,
  29. // rollingInterval: RollingInterval.Day,//()
  30. // //fileSizeLimitBytes: 20971520, //õļСΪ3M Ĭ1G
  31. // rollOnFileSizeLimit: true, //ļС󴴽µ
  32. // retainedFileCountLimit: 7,//Ĭ31˼ֻ31־ļ"
  33. // outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff}[{Level:u3}] [Thread-{ThreadId}] [{SourceContext:l}] {Message:lj}{NewLine}{Exception}"
  34. // )
  35. // )
  36. // .WriteTo.Async(c => c.File("/var/telpo_pushthird_ssl2/logs/errors/errors.log",
  37. // restrictedToMinimumLevel: LogEventLevel.Error,
  38. // rollingInterval: RollingInterval.Day,
  39. // rollOnFileSizeLimit: true,
  40. // retainedFileCountLimit: 7,
  41. // outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff }[{Level:u3}] [Thread-{ThreadId}] [{SourceContext:l}] {Message:lj}{NewLine}{Exception}"
  42. // )
  43. // )
  44. // .WriteTo.Async(c => c.Console())
  45. // .CreateLogger();
  46. //ѡļappsetting.json
  47. var configuration = new ConfigurationBuilder()
  48. .SetBasePath(Directory.GetCurrentDirectory())
  49. .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
  50. .Build();
  51. Log.Logger = new LoggerConfiguration()
  52. .ReadFrom.Configuration(configuration)
  53. .Enrich.WithThreadId()
  54. .CreateLogger();
  55. #endregion
  56. Log.Information("Starting up");
  57. var builder = Host.CreateApplicationBuilder(args);
  58. var config = builder.Configuration;
  59. builder.Services.Configure<FenceConfig>(config.GetSection("FenceConfig"));
  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<IKafkaService, KafkaService>();
  79. builder.Services.AddSingleton<KafkaSubscribe>();
  80. builder.Services.AddSingleton<MessageProducer>();
  81. builder.Services.AddSingleton<MqProcessMessage>();
  82. builder.Services.AddSingleton<FenceProcess>();
  83. builder.Services.AddHostedService<Worker>();
  84. var host = builder.Build();
  85. host.Run();
  86. }
  87. catch (Exception ex)
  88. {
  89. Log.Fatal(ex, "Application start-up failed");
  90. }
  91. finally
  92. {
  93. Log.CloseAndFlush();
  94. }