Skip to content

Instantly share code, notes, and snippets.

@hgmauri
Created February 28, 2024 12:43
Show Gist options
  • Save hgmauri/079e6bc44efdd114ce3ec7e84c530121 to your computer and use it in GitHub Desktop.
Save hgmauri/079e6bc44efdd114ce3ec7e84c530121 to your computer and use it in GitHub Desktop.
Program.cs
try
{
var builder = WebApplication.CreateBuilder(args);
builder.AddSerilogApi(builder.Configuration);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddExceptionHandler<ErrorHandlingMiddleware>();
builder.Services.AddProblemDetails();
var app = builder.Build();
app.UseExceptionHandler(opt => { });
app.UseAuthorization();
app.MapControllers();
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
Log.Information("Server Shutting down...");
Log.CloseAndFlush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment