Advertisement
Guest User

Untitled

a guest
Nov 13th, 2021
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. using System;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.Extensions.Hosting;
  4. using Serilog;
  5. using Serilog.Events;
  6.  
  7. namespace OnlineService
  8. {
  9. public class Program
  10. {
  11. public static int Main(string[] args)
  12. {
  13. Log.Logger = new LoggerConfiguration()
  14. #if DEBUG
  15. .MinimumLevel.Debug()
  16. #else
  17. .MinimumLevel.Information()
  18. #endif
  19. .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
  20. .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
  21. .Enrich.FromLogContext()
  22. .WriteTo.Async(c => c.File("Logs/logs.txt"))
  23. #if DEBUG
  24. .WriteTo.Async(c => c.Console())
  25. #endif
  26. .CreateLogger();
  27.  
  28. try
  29. {
  30. Log.Information("Starting OnlineService.HttpApi.Host.");
  31. CreateHostBuilder(args).Build().Run();
  32. return 0;
  33. }
  34. catch (Exception ex)
  35. {
  36. Log.Fatal(ex, "Host terminated unexpectedly!");
  37. return 1;
  38. }
  39. finally
  40. {
  41. Log.CloseAndFlush();
  42. }
  43. }
  44.  
  45. internal static IHostBuilder CreateHostBuilder(string[] args) =>
  46. Host.CreateDefaultBuilder(args)
  47. .ConfigureWebHostDefaults(webBuilder =>
  48. {
  49. webBuilder.UseStartup<Startup>();
  50. })
  51. .UseAutofac()
  52. .UseSerilog();
  53. }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement