48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
|
|
using Serilog.Events;
|
||
|
|
|
||
|
|
namespace JiShe.ServicePro;
|
||
|
|
|
||
|
|
public class Program
|
||
|
|
{
|
||
|
|
public static async Task<int> Main(string[] args)
|
||
|
|
{
|
||
|
|
Log.Logger = new LoggerConfiguration()
|
||
|
|
.WriteTo.Async(c => c.File("Logs/logs.txt"))
|
||
|
|
.WriteTo.Async(c => c.Console())
|
||
|
|
.CreateBootstrapLogger();
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
Log.Information("JiShe.ServicePro.HttpApi.Host.");
|
||
|
|
var builder = WebApplication.CreateBuilder(args);
|
||
|
|
builder.Host
|
||
|
|
.AddAppSettingsSecretsJson()
|
||
|
|
.UseAutofac()
|
||
|
|
.UseSerilog((context, loggerConfiguration) =>
|
||
|
|
{
|
||
|
|
SerilogToEsExtensions.SetSerilogConfiguration(
|
||
|
|
loggerConfiguration,
|
||
|
|
context.Configuration);
|
||
|
|
});
|
||
|
|
await builder.AddApplicationAsync<JiShe.ServicePro.ServiceProHttpApiHostModule>();
|
||
|
|
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();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|