Added logging nuget packages to allow for logging capabilities.
This commit is contained in:
@ -1,6 +1,16 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using ReportingServices.Dependency_Injections;
|
||||
using Serilog;
|
||||
|
||||
LoggerConfiguration loggerConfiguration = new();
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
Environment.SetEnvironmentVariable("workingDirectory", "C:/tmp/logging");
|
||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, builder.Configuration);
|
||||
_ = SerilogHostBuilderExtensions.UseSerilog(builder.Host);
|
||||
Log.Logger = loggerConfiguration.CreateLogger();
|
||||
Serilog.ILogger log = Log.ForContext<Program>();
|
||||
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
@ -28,5 +38,17 @@ app.UseAuthorization();
|
||||
app.MapControllerRoute(
|
||||
name: "default",
|
||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
app.Run();
|
||||
_ = app.Lifetime.ApplicationStopped.Register(Log.CloseAndFlush);
|
||||
log.Information("Starting Web Application");
|
||||
try
|
||||
{
|
||||
app.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.Fatal(ex, "Host terminated unexpectedly");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
|
Reference in New Issue
Block a user