chore 抽象微服务基本类库

This commit is contained in:
2025-10-03 18:04:57 +08:00
parent 886cec11fb
commit c667df1ce3
34 changed files with 1335 additions and 323 deletions

View File

@ -1,56 +1,28 @@
using System;
using System.Threading.Tasks;
using KonSoft.Admin;
using KonSoft.Shared.Hosting.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using System;
namespace KonSoft.Admin;
var assemblyName = typeof(Program).Assembly.GetName().Name!;
public class Program
SerilogConfigurationHelper.Configure(assemblyName);
try
{
public async static Task<int> Main(string[] args)
{
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()
.WriteTo.Async(c => c.File("Logs/logs.txt"))
.WriteTo.Async(c => c.Console())
.CreateLogger();
Log.Information($"Starting {assemblyName}.");
var app = await ApplicationBuilderHelper
.BuildApplicationAsync<AdminHttpApiHostModule>(args);
await app.InitializeApplicationAsync();
await app.RunAsync();
try
{
Log.Information("Starting KonSoft.Admin.HttpApi.Host.");
var builder = WebApplication.CreateBuilder(args);
builder.Host.AddAppSettingsSecretsJson()
.UseAutofac()
.UseSerilog();
await builder.AddApplicationAsync<AdminHttpApiHostModule>();
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
{
Log.CloseAndFlush();
}
}
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, $"{assemblyName} terminated unexpectedly!");
return 1;
}
finally
{
await Log.CloseAndFlushAsync();
}