定位推送服务
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

98 lines
3.6KB

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