|
@@ -1,30 +1,49 @@
|
|
|
-using FileHandlers;
|
|
|
using FileStorage.Host;
|
|
|
-
|
|
|
-var builder = WebApplication.CreateBuilder(args);
|
|
|
-
|
|
|
-// Add services to the container.
|
|
|
-
|
|
|
-builder.Services.AddControllers();
|
|
|
-// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
-builder.Services.AddEndpointsApiExplorer();
|
|
|
-builder.Services.AddSwaggerGen();
|
|
|
-
|
|
|
-builder.ConfigureServices().ConfigurePipelines().Run();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-//var app = builder.Build();
|
|
|
-
|
|
|
-//// Configure the HTTP request pipeline.
|
|
|
-//if (app.Environment.IsDevelopment())
|
|
|
-//{
|
|
|
-// app.UseSwagger();
|
|
|
-// app.UseSwaggerUI();
|
|
|
-//}
|
|
|
-
|
|
|
-//app.UseAuthorization();
|
|
|
-
|
|
|
-//app.MapControllers();
|
|
|
-
|
|
|
-//app.Run();
|
|
|
+using Serilog;
|
|
|
+
|
|
|
+Log.Logger = new LoggerConfiguration()
|
|
|
+ .WriteTo.Console()
|
|
|
+ .CreateBootstrapLogger();
|
|
|
+
|
|
|
+Log.Information("FileStorage service is Starting up");
|
|
|
+
|
|
|
+try
|
|
|
+{
|
|
|
+ var builder = WebApplication.CreateBuilder(args);
|
|
|
+
|
|
|
+ builder.Host
|
|
|
+ .ConfigureAppConfiguration((hostBuilderContext, configBuilder) =>
|
|
|
+ {
|
|
|
+ var path = Path.Combine(Directory.GetCurrentDirectory(), "config");
|
|
|
+ configBuilder.SetBasePath(path)
|
|
|
+#if DEBUG
|
|
|
+ .AddJsonFile("appsettings.shared.Development.json", true, true)
|
|
|
+#else
|
|
|
+ .AddJsonFile("appsettings.shared.json", true, true)
|
|
|
+#endif
|
|
|
+ .AddJsonFile("appsettings.json", false, true)
|
|
|
+ .AddJsonFile($"appsettings.{hostBuilderContext.HostingEnvironment.EnvironmentName}.json", true, true)
|
|
|
+ .AddEnvironmentVariables()
|
|
|
+ .AddCommandLine(args)
|
|
|
+ ;
|
|
|
+ })
|
|
|
+ .UseSerilog((ctx, lc) => lc
|
|
|
+ //.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}")
|
|
|
+ .Enrich.FromLogContext()
|
|
|
+ .ReadFrom.Configuration(ctx.Configuration))
|
|
|
+ ;
|
|
|
+
|
|
|
+ builder
|
|
|
+ .ConfigureServices()
|
|
|
+ .ConfigurePipelines()
|
|
|
+ .Run();
|
|
|
+}
|
|
|
+catch (Exception ex)
|
|
|
+{
|
|
|
+ Log.Fatal(ex, "Unhandled exception");
|
|
|
+}
|
|
|
+finally
|
|
|
+{
|
|
|
+ Log.Information("Shut down complete");
|
|
|
+ Log.CloseAndFlush();
|
|
|
+}
|