chore: 优化authserver代码

This commit is contained in:
2025-10-25 14:39:24 +08:00
parent 0f55e2e108
commit a695a21bcb
12 changed files with 115 additions and 52 deletions

View File

@ -1,10 +1,8 @@
using System;
using System.Threading.Tasks;
using KonSoft.Shared.Hosting.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using System;
using System.Threading.Tasks;
namespace KonSoft;
@ -12,45 +10,27 @@ public class Program
{
public static async 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();
var assemblyName = typeof(Program).Assembly.GetName().Name!;
SerilogConfigurationHelper.Configure(assemblyName);
try
{
Log.Information("Starting KonSoft.AuthServer.");
var builder = WebApplication.CreateBuilder(args);
builder.Host.AddAppSettingsSecretsJson()
.UseAutofac()
.UseSerilog();
await builder.AddApplicationAsync<KonSoftAuthServerModule>();
var app = builder.Build();
Log.Information($"Starting {assemblyName}.");
var app = await ApplicationBuilderHelper
.BuildApplicationAsync<KonSoftAuthServerModule>(args);
await app.InitializeApplicationAsync();
await app.RunAsync();
return 0;
}
catch (Exception ex)
{
if (ex is HostAbortedException)
{
throw;
}
Log.Fatal(ex, "KonSoft.AuthServer terminated unexpectedly!");
Log.Fatal(ex, $"{assemblyName} terminated unexpectedly!");
return 1;
}
finally
{
Log.CloseAndFlush();
await Log.CloseAndFlushAsync();
}
}
}