Guest User

Untitled

a guest
Sep 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime, IRequestContext requestContext)
  2. {
  3. loggerFactory.AddSerilog();
  4.  
  5. // Ensure any buffered events are sent at shutdown
  6. appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);
  7.  
  8. var logger = loggerFactory.CreateLogger<Startup>();
  9.  
  10. app.UseExceptionHandler(
  11. options =>
  12. {
  13. options.Run(
  14. async context =>
  15. {
  16. context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
  17. var ex = context.Features.Get<IExceptionHandlerFeature>();
  18. if (ex != null)
  19. {
  20. var errmsg = "An unexpected error has occured in API.";
  21. var logDetails = new
  22. {
  23. CorrelationId = requestContext.CorrelationId,
  24. Message = errmsg
  25. };
  26. logger.LogError(1001, ex.Error, "{@LogDetails}", logDetails);
  27. await context.Response.WriteAsync(errmsg).ConfigureAwait(false);
  28. }
  29. });
  30. });
  31.  
  32. app.UseMvc();
  33.  
  34. logger.LogInformation("Application has started in environment {0}", env.EnvironmentName);
  35. }
Add Comment
Please, Sign In to add comment