|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- using Serilog;
- using TelpoDataService.Util.Clients;
- using TelpoPush.Common;
- using TelpoPush.Models.Config;
- using TelpoPush.Service.Biz;
- using TelpoPush.Service.Cache;
- using TelpoPush.Service.Mq.Kafka;
- using TelpoPush.Worker.ThirdSsl;
- using TelpoPush.Worker.ThirdSsl.Handlers;
-
-
- #region ־
- //using Serilog.Events;
- //using Serilog;
- //using Microsoft.AspNetCore.Builder;
-
- //Log.Logger = new LoggerConfiguration()
- //#if DEBUG
- // .MinimumLevel.Debug()
- //#else
- // .MinimumLevel.Information()
- //#endif
- // .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
- // .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
- // .Enrich.FromLogContext()
- // //.Filter.ByExcluding(c => c.Properties.Any(p => p.Value.ToString().Contains("Microsoft")))//
- // .WriteTo.Async(c => c.File("/var/telpo_pushthird_ssl2/logs/infos/info.log",
- // restrictedToMinimumLevel: LogEventLevel.Information,
- // rollingInterval: RollingInterval.Day,//()
- // //fileSizeLimitBytes: 20971520, //õļСΪ3M Ĭ1G
- // rollOnFileSizeLimit: true, //ļСµ
- // retainedFileCountLimit: 7,//Ĭ31˼ֻ31־ļ"
- // outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff}[{Level:u3}] [Thread-{ThreadId}] [{SourceContext:l}] {Message:lj}{NewLine}{Exception}"
- // )
- // )
- // .WriteTo.Async(c => c.File("/var/telpo_pushthird_ssl2/logs/errors/errors.log",
- // restrictedToMinimumLevel: LogEventLevel.Error,
- // rollingInterval: RollingInterval.Day,
- // rollOnFileSizeLimit: true,
- // retainedFileCountLimit: 7,
- // outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff }[{Level:u3}] [Thread-{ThreadId}] [{SourceContext:l}] {Message:lj}{NewLine}{Exception}"
- // )
- // )
- // .WriteTo.Async(c => c.Console())
- // .CreateLogger();
-
- //ѡļappsetting.json
- var configuration = new ConfigurationBuilder()
- .SetBasePath(Directory.GetCurrentDirectory())
- .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- .Build();
-
- Log.Logger = new LoggerConfiguration()
- .ReadFrom.Configuration(configuration)
- .Enrich.WithThreadId()
- .CreateLogger();
- #endregion
- try
- {
- Log.Information("Starting up");
- var builder = Host.CreateApplicationBuilder(args);
-
- var config = builder.Configuration;
- builder.Services.Configure<ServiceConfig>(config.GetSection("ServiceConfig"));
- builder.Services.Configure<RedisConfig>(config.GetSection("Redis"));
-
- JsonSerializerSettings setting = new JsonSerializerSettings();
- JsonConvert.DefaultSettings = () =>
- {
- setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
- setting.ContractResolver = new CamelCasePropertyNamesContractResolver();
- return setting;
- };
- builder.Services.AddTelpoDataServices(opt =>
- {
- opt.TelpoDataUrl = config["ServiceConfig:TelpoDataUrl"];
- });
-
- builder.Services.AddSerilog();
- builder.Services.AddHttpClient();
- builder.Services.AddTransient<HttpHelperAsync>();
- builder.Services.AddSingleton<SqlMapper>();
- builder.Services.AddSingleton<RedisUtil>();
- builder.Services.AddSingleton<IZkRealHRMonitorService, ZkRealHRMonitorService>();
- builder.Services.AddSingleton<IKafkaService, KafkaService>();
- builder.Services.AddSingleton<KafkaSubscribe>();
- builder.Services.AddSingleton<MessageProducer>();
- builder.Services.AddSingleton<MqProcessMessage>();
- builder.Services.AddSingleton<ThirdSslProcess>();
- builder.Services.AddHostedService<Worker>();
- var host = builder.Build();
- host.Run();
- }
- catch (Exception ex)
- {
- Log.Fatal(ex, "Application start-up failed");
- }
- finally
- {
- Log.CloseAndFlush();
- }
|