定位推送服务

Program.cs 3.8KB

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