Update database error page to react to EF logging changes.

This commit is contained in:
Arthur Vickers 2017-05-15 16:09:56 -07:00
parent 7199e8d358
commit 44610a44ac
1 changed files with 11 additions and 3 deletions

View File

@ -3,9 +3,13 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Utilities; using Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.Utilities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
@ -34,10 +38,14 @@ namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
public virtual void Log<TState>(LogLevel logLevel, EventId eventId, [CanBeNull] TState state, [CanBeNull] Exception exception, [CanBeNull] Func<TState, Exception, string> formatter) public virtual void Log<TState>(LogLevel logLevel, EventId eventId, [CanBeNull] TState state, [CanBeNull] Exception exception, [CanBeNull] Func<TState, Exception, string> formatter)
{ {
var errorState = state as DatabaseErrorLogState; if (exception != null
if (errorState != null && exception != null && LastError != null) && LastError != null
&& (eventId.Id == CoreEventId.SaveChangesFailed.Id
|| eventId.Id == CoreEventId.QueryIterationFailed.Id))
{ {
LastError.SetError(errorState.ContextType, exception); LastError.SetError(
(Type)((IReadOnlyList<KeyValuePair<string, object>>)state).Single(p => p.Key == "contextType").Value,
exception);
} }
} }