|
-
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- using Serilog;
- using TelpoDataService.Util.Clients;
- using TelpoPush.WanJiaAn.Worker;
- using TelpoPush.WanJiaAn.Worker.Common;
- using TelpoPush.WanJiaAn.Worker.Handlers;
- using TelpoPush.WanJiaAn.Worker.Models.Config;
- using TelpoPush.WanJiaAn.Worker.Service.Cache;
- using TelpoPush.WanJiaAn.Worker.Service.Mq;
-
-
- #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<WanJiaAnConfig>(config.GetSection("WanJiaAnConfig"));
- 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<IKafkaService, KafkaService>();
- builder.Services.AddSingleton<KafkaSubscribe>();
- builder.Services.AddSingleton<MessageProducer>();
- builder.Services.AddSingleton<MqProcessMessage>();
- builder.Services.AddSingleton<WanJiaAnProcess>();
- builder.Services.AddHostedService<Worker>();
- var host = builder.Build();
- host.Run();
- }
- catch (Exception ex)
- {
- Log.Fatal(ex, "Application start-up failed");
- }
- finally
- {
- Log.CloseAndFlush();
- }
|