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.
62 lines
1.8 KiB
62 lines
1.8 KiB
using Microsoft.AspNetCore.Builder; |
|
using Microsoft.Extensions.DependencyInjection; |
|
using Microsoft.Extensions.Hosting; |
|
using Serilog; |
|
using Serilog.Events; |
|
using System; |
|
using System.Threading.Tasks; |
|
|
|
namespace BookStore; |
|
|
|
public class Program |
|
{ |
|
public async static Task<int> Main(string[] args) |
|
{ |
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); |
|
var loggerConfiguration = new LoggerConfiguration() |
|
#if DEBUG |
|
.MinimumLevel.Debug() |
|
#else |
|
.MinimumLevel.Information() |
|
#endif |
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) |
|
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) |
|
.Enrich.FromLogContext() |
|
#if DEBUG |
|
.WriteTo.Async(c => c.File("Logs/logs.txt")) |
|
.WriteTo.Async(c => c.Console()); |
|
#else |
|
.WriteTo.Async(c => c.File("Logs/logs.txt")); |
|
#endif |
|
Log.Logger = loggerConfiguration.CreateLogger(); |
|
|
|
try |
|
{ |
|
var builder = WebApplication.CreateBuilder(args); |
|
builder.Host.AddAppSettingsSecretsJson() |
|
.UseAutofac() |
|
.UseSerilog(); |
|
await builder.AddApplicationAsync<BookStoreModule>(); |
|
var app = builder.Build(); |
|
await app.InitializeApplicationAsync(); |
|
|
|
Log.Information("Starting BookStore."); |
|
await app.RunAsync(); |
|
return 0; |
|
} |
|
catch (Exception ex) |
|
{ |
|
if (ex.GetType().Name.Equals("StopTheHostException", StringComparison.Ordinal)) |
|
{ |
|
throw; |
|
} |
|
|
|
Log.Fatal(ex, "BookStore terminated unexpectedly!"); |
|
return 1; |
|
} |
|
finally |
|
{ |
|
Log.CloseAndFlush(); |
|
} |
|
} |
|
}
|
|
|