定位推送服务
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.

102 lines
3.7KB

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