From 6917604fec9825e15724e6b1e500b2740bd65e3d Mon Sep 17 00:00:00 2001 From: "zzzwangjun@gmail.com" <510423039@qq.com> Date: Fri, 12 Sep 2025 17:18:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Program.cs | 46 +++++++++++++------ .../Startup.cs | 16 ------- 2 files changed, 32 insertions(+), 30 deletions(-) delete mode 100644 templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Startup.cs diff --git a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Program.cs b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Program.cs index c10267e9..a29ba1fe 100644 --- a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Program.cs +++ b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Program.cs @@ -1,25 +1,43 @@ namespace MyCompanyName.MyProjectName { public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - - } + { + Log.Logger = new LoggerConfiguration() + .WriteTo.Async(c => c.File("Logs/logs.txt")) + .WriteTo.Async(c => c.Console()) + .CreateBootstrapLogger(); - private static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.ConfigureKestrel((context, options) => { options.Limits.MaxRequestBodySize = 1024 * 50; }); - webBuilder.UseStartup(); - }) + try + { + var builder = WebApplication.CreateBuilder(args); + builder.Host + .AddAppSettingsSecretsJson() + .UseAutofac() .UseSerilog((context, loggerConfiguration) => { SerilogToEsExtensions.SetSerilogConfiguration( loggerConfiguration, context.Configuration); - }).UseAutofac(); + }); + await builder.AddApplicationAsync(); + var app = builder.Build(); + await app.InitializeApplicationAsync(); + await app.RunAsync(); + return 0; + } + catch (Exception ex) + { + if (ex is HostAbortedException) + { + throw; + } + + Log.Fatal(ex, "Host terminated unexpectedly!"); + return 1; + } + finally + { + await Log.CloseAndFlushAsync(); + } } } diff --git a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Startup.cs b/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Startup.cs deleted file mode 100644 index 0b4fd9f2..00000000 --- a/templates/pro-nuget/service/host/MyCompanyName.MyProjectName.HttpApi.Host/Startup.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace MyCompanyName.MyProjectName -{ - public class Startup - { - public void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - - } - } -}