You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.0 KiB
69 lines
2.0 KiB
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Serilog;
|
|
using Serilog.Events;
|
|
using Shentun.Utilities;
|
|
|
|
namespace Shentun.WebPeis;
|
|
|
|
public class Program
|
|
{
|
|
public async static Task<int> Main(string[] args)
|
|
{
|
|
var configuration = new ConfigurationBuilder()
|
|
.SetBasePath(DirectoryHelper.GetAppDirectory())
|
|
.AddJsonFile("Serilog.json", false, reloadOnChange: true)
|
|
.Build();
|
|
|
|
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())
|
|
.ReadFrom.Configuration(configuration)
|
|
.CreateLogger();
|
|
|
|
try
|
|
{
|
|
Log.Information("Starting Shentun.WebPeis.HttpApi.Host.");
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
builder.Host.AddAppSettingsSecretsJson()
|
|
.UseAutofac()
|
|
.UseSerilog();
|
|
await builder.AddApplicationAsync<WebPeisHttpApiHostModule>();
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|