diff --git a/src/Microsoft.AspNet.Diagnostics/ErrorPageExtensions.cs b/src/Microsoft.AspNet.Diagnostics/ErrorPageExtensions.cs
index 4a48d1d9f2..5696387521 100644
--- a/src/Microsoft.AspNet.Diagnostics/ErrorPageExtensions.cs
+++ b/src/Microsoft.AspNet.Diagnostics/ErrorPageExtensions.cs
@@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Builder
///
public static IApplicationBuilder UseErrorPage([NotNull] this IApplicationBuilder builder, ErrorPageOptions options)
{
- return builder.Use(next => new ErrorPageMiddleware(next, options).Invoke);
+ return builder.UseMiddleware(options);
}
}
}
diff --git a/src/Microsoft.AspNet.Diagnostics/ErrorPageMiddleware.cs b/src/Microsoft.AspNet.Diagnostics/ErrorPageMiddleware.cs
index 62418b58cf..cac641a8cb 100644
--- a/src/Microsoft.AspNet.Diagnostics/ErrorPageMiddleware.cs
+++ b/src/Microsoft.AspNet.Diagnostics/ErrorPageMiddleware.cs
@@ -13,6 +13,7 @@ using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics.Views;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
+using Microsoft.Framework.Logging;
using Microsoft.Framework.Runtime;
namespace Microsoft.AspNet.Diagnostics
@@ -25,16 +26,19 @@ namespace Microsoft.AspNet.Diagnostics
private readonly RequestDelegate _next;
private readonly ErrorPageOptions _options;
private static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
+ private readonly ILogger _logger;
///
/// Initializes a new instance of the class
///
///
///
- public ErrorPageMiddleware([NotNull] RequestDelegate next, [NotNull] ErrorPageOptions options)
+ public ErrorPageMiddleware(
+ [NotNull] RequestDelegate next, [NotNull] ErrorPageOptions options, ILoggerFactory loggerFactory)
{
_next = next;
_options = options;
+ _logger = loggerFactory.CreateLogger();
}
///
@@ -51,14 +55,16 @@ namespace Microsoft.AspNet.Diagnostics
}
catch (Exception ex)
{
+ _logger.LogError("An unhandled exception has occurred while executing the request", ex);
try
{
await DisplayException(context, ex);
return;
}
- catch (Exception)
+ catch (Exception ex2)
{
// 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;
}