Program.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Hotline.Api;
  2. using Serilog;
  3. Log.Logger = new LoggerConfiguration()
  4. .WriteTo.Console()
  5. .CreateBootstrapLogger();
  6. try
  7. {
  8. Log.Information("Hotline service is Starting up");
  9. var builder = WebApplication.CreateBuilder(args);
  10. builder.Host
  11. .ConfigureAppConfiguration((hostBuilderContext, configBuilder) =>
  12. {
  13. var path = Path.Combine(Directory.GetCurrentDirectory(), "config");
  14. configBuilder.SetBasePath(path)
  15. #if DEBUG
  16. .AddJsonFile("appsettings.shared.Development.json", true, true)
  17. #else
  18. .AddJsonFile("appsettings.shared.json", true, true)
  19. #endif
  20. .AddJsonFile("appsettings.json", false, true)
  21. .AddJsonFile($"appsettings.{hostBuilderContext.HostingEnvironment.EnvironmentName}.json", true, true)
  22. .AddEnvironmentVariables()
  23. .AddCommandLine(args)
  24. ;
  25. })
  26. .UseSerilog((ctx, lc) => lc
  27. //.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}")
  28. .Enrich.FromLogContext()
  29. .ReadFrom.Configuration(ctx.Configuration), true)
  30. ;
  31. builder
  32. .ConfigureServices()
  33. .ConfigurePipelines()
  34. .Run();
  35. }
  36. catch (Exception ex)
  37. {
  38. Log.Fatal(ex, "Unhandled exception");
  39. }
  40. finally
  41. {
  42. Log.Information("Shut down complete");
  43. Log.CloseAndFlush();
  44. }