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(config.GetSection("ServiceConfig")); builder.Services.Configure(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(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddHostedService(); var host = builder.Build(); host.Run(); } catch (Exception ex) { Log.Fatal(ex, "Application start-up failed"); } finally { Log.CloseAndFlush(); }