Added logging to ErrorPageMiddleware
This commit is contained in:
parent
236d4009c3
commit
7c287c8712
|
|
@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Builder
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseErrorPage([NotNull] this IApplicationBuilder builder, ErrorPageOptions options)
|
public static IApplicationBuilder UseErrorPage([NotNull] this IApplicationBuilder builder, ErrorPageOptions options)
|
||||||
{
|
{
|
||||||
return builder.Use(next => new ErrorPageMiddleware(next, options).Invoke);
|
return builder.UseMiddleware<ErrorPageMiddleware>(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Diagnostics.Views;
|
using Microsoft.AspNet.Diagnostics.Views;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.Framework.Internal;
|
using Microsoft.Framework.Internal;
|
||||||
|
using Microsoft.Framework.Logging;
|
||||||
using Microsoft.Framework.Runtime;
|
using Microsoft.Framework.Runtime;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Diagnostics
|
namespace Microsoft.AspNet.Diagnostics
|
||||||
|
|
@ -25,16 +26,19 @@ namespace Microsoft.AspNet.Diagnostics
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private readonly ErrorPageOptions _options;
|
private readonly ErrorPageOptions _options;
|
||||||
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
|
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
|
/// Initializes a new instance of the <see cref="ErrorPageMiddleware"/> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="next"></param>
|
/// <param name="next"></param>
|
||||||
/// <param name="options"></param>
|
/// <param name="options"></param>
|
||||||
public ErrorPageMiddleware([NotNull] RequestDelegate next, [NotNull] ErrorPageOptions options)
|
public ErrorPageMiddleware(
|
||||||
|
[NotNull] RequestDelegate next, [NotNull] ErrorPageOptions options, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
_options = options;
|
_options = options;
|
||||||
|
_logger = loggerFactory.CreateLogger<ErrorPageMiddleware>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -51,14 +55,16 @@ namespace Microsoft.AspNet.Diagnostics
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
_logger.LogError("An unhandled exception has occurred while executing the request", ex);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await DisplayException(context, ex);
|
await DisplayException(context, ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex2)
|
||||||
{
|
{
|
||||||
// If there's a Exception while generating the error page, re-throw the original exception.
|
// If there's a Exception while generating the error page, re-throw the original exception.
|
||||||
|
_logger.LogError("An exception was thrown attempting to display the error page.", ex2);
|
||||||
}
|
}
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue