Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime appLifetime, IRequestContext requestContext)
- {
- loggerFactory.AddSerilog();
- // Ensure any buffered events are sent at shutdown
- appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);
- var logger = loggerFactory.CreateLogger<Startup>();
- app.UseExceptionHandler(
- options =>
- {
- options.Run(
- async context =>
- {
- context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
- var ex = context.Features.Get<IExceptionHandlerFeature>();
- if (ex != null)
- {
- var errmsg = "An unexpected error has occured in API.";
- var logDetails = new
- {
- CorrelationId = requestContext.CorrelationId,
- Message = errmsg
- };
- logger.LogError(1001, ex.Error, "{@LogDetails}", logDetails);
- await context.Response.WriteAsync(errmsg).ConfigureAwait(false);
- }
- });
- });
- app.UseMvc();
- logger.LogInformation("Application has started in environment {0}", env.EnvironmentName);
- }
Add Comment
Please, Sign In to add comment