using Microsoft.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Opsoft.NetCore.O3App.Infrastructure; using Serilog; using Serilog.Events; using System; using System.IO; using System.Threading; namespace Opsoft.NetCore.O3App.WebApi { class Program { static void Main(string[] args) { ThreadPool.GetMaxThreads(out var workerThreads, out var ioThreads); Console.WriteLine("MaxThreads \t workerThreads:{0} \t ioThreads:{1}", workerThreads, ioThreads); ThreadPool.GetMinThreads(out workerThreads, out ioThreads); workerThreads *= 8; ioThreads *= 8; ThreadPool.SetMinThreads(workerThreads, ioThreads); Console.WriteLine("MinThreads \t workerThreads:{0} \t ioThreads:{1}", workerThreads, ioThreads); var builder = new HostBuilder(); builder.ConfigureWebHostDefaults(webBuilder => { webBuilder .ConfigureServices(ServiceRegister.RegisteServices) .ConfigureAppConfiguration(ConfigureAppConfiguration) .UseSerilog(UseSkynetLogger) //.UseDefaultServiceProvider((context, options) => options.ValidateScopes = context.HostingEnvironment.IsDevelopment()) .UseStartup(); }); builder //.ConfigureEnvironment() .UseContentRoot(Directory.GetCurrentDirectory()) //.UseServiceDegradation() ; builder.Build().Run(); //WebHost.CreateDefaultBuilder(args) // .ConfigureServices(s => s.AddHostedService()) // .UseDaokeEnvironment() // .UseApm() // .UseContentRoot(Directory.GetCurrentDirectory()) // .UseKestrel() // .ConfigureAppConfiguration(ConfigureAppConfiguration) // .ConfigureServices(ServiceRegister.RegisteServices) // .UseDefaultServiceProvider((context, options) => options.ValidateScopes = context.HostingEnvironment.IsDevelopment()) // .UseHealthCheck(HealthStatus.Online) // .UseSerilog(UseSkynetLogger) // .UseStartup() // .Build() // .Run(); } private static void UseSkynetLogger(WebHostBuilderContext context, LoggerConfiguration configuration) { string logPath = $"/data/logs/skynet-{context.HostingEnvironment.EnvironmentName}/logs/app.log"; long? fileSizeLimitBytes = 104857600; bool buffered = false; bool shared = true; TimeSpan? flushToDiskInterval = null; bool rollOnFileSizeLimit = true; int? retainedFileCountLimit = 640; configuration .MinimumLevel.Verbose() .MinimumLevel.Override(nameof(System), LogEventLevel.Error) .MinimumLevel.Override(nameof(Microsoft), LogEventLevel.Error); configuration.Filter.With(new SkynetLoggerFilter(context.Configuration)); configuration.Enrich.With(new SkynetEnricher()) .WriteTo.File(new SkynetLoggerFormatter(), logPath, LogEventLevel.Verbose, fileSizeLimitBytes, null, buffered, shared, flushToDiskInterval, RollingInterval.Day, rollOnFileSizeLimit, retainedFileCountLimit); } private static void ConfigureAppConfiguration(WebHostBuilderContext context, IConfigurationBuilder builder) { var env = context.HostingEnvironment.EnvironmentName; builder .AddEnvironmentVariables() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile($"appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: true); } } }