Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. using Microsoft.AspNetCore;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Serilog;
  4. using Serilog.Events;
  5. using System;
  6.  
  7. namespace test
  8. {
  9. public class Program
  10. {
  11. public static int Main(string[] args)
  12. {
  13. //Specify the template to use via Console
  14. Log.Logger = new LoggerConfiguration()
  15. .MinimumLevel.Debug()
  16. .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
  17. .Enrich.FromLogContext()
  18. .WriteTo.Console(outputTemplate: "[{Timestamp:yyyy-MMM-dd HH:mm:ss.fff}] [{Level}] {Message}{NewLine}{Exception}")
  19. .CreateLogger();
  20.  
  21. try
  22. {
  23. Log.Information("Starting web host");
  24. BuildWebHost(args).Run();
  25. return 0;
  26. }
  27. catch (Exception ex)
  28. {
  29. Log.Fatal(ex, "Host terminated unexpectedly");
  30. return 1;
  31. }
  32. finally
  33. {
  34. Log.CloseAndFlush();
  35. }
  36. }
  37.  
  38. //Use serilog here
  39. public static IWebHost BuildWebHost(string[] args) =>
  40. WebHost.CreateDefaultBuilder(args)
  41. .UseStartup<Startup>()
  42. .UseSerilog()
  43. .Build();
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement