React to Logging API changes
This commit is contained in:
parent
1a70f12bf8
commit
3cac63a9cf
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
|
@ -368,7 +369,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
_redirectToRouteResultExecuting(logger, destination, routeName, null);
|
||||
}
|
||||
|
||||
private class ActionLogScope : ILogValues
|
||||
private class ActionLogScope : IReadOnlyList<KeyValuePair<string, object>>
|
||||
{
|
||||
private readonly ActionDescriptor _action;
|
||||
|
||||
|
|
@ -382,13 +383,36 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
_action = action;
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<string, object>> GetValues()
|
||||
public KeyValuePair<string, object> this[int index]
|
||||
{
|
||||
return new KeyValuePair<string, object>[]
|
||||
get
|
||||
{
|
||||
new KeyValuePair<string, object>("ActionId", _action.Id),
|
||||
new KeyValuePair<string, object>("ActionName", _action.DisplayName),
|
||||
};
|
||||
if (index == 0)
|
||||
{
|
||||
return new KeyValuePair<string, object>("ActionId", _action.Id);
|
||||
}
|
||||
else if (index == 1)
|
||||
{
|
||||
return new KeyValuePair<string, object>("ActionName", _action.DisplayName);
|
||||
}
|
||||
throw new IndexOutOfRangeException(nameof(index));
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < Count; ++i)
|
||||
{
|
||||
yield return this[i];
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
@ -397,6 +421,11 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
// you have text logging, you can already use the requestId for correlation.
|
||||
return _action.DisplayName;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.AspNetCore.Mvc.ViewComponents;
|
||||
|
|
@ -192,7 +193,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
_viewNotFound(logger, viewName, searchedLocations, null);
|
||||
}
|
||||
|
||||
private class ViewComponentLogScope : ILogValues
|
||||
private class ViewComponentLogScope : IReadOnlyList<KeyValuePair<string, object>>
|
||||
{
|
||||
private readonly ViewComponentDescriptor _descriptor;
|
||||
|
||||
|
|
@ -201,19 +202,47 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
|
|||
_descriptor = descriptor;
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<string, object>> GetValues()
|
||||
public KeyValuePair<string, object> this[int index]
|
||||
{
|
||||
return new KeyValuePair<string, object>[]
|
||||
get
|
||||
{
|
||||
new KeyValuePair<string, object>("ViewComponentName", _descriptor.DisplayName),
|
||||
new KeyValuePair<string, object>("ViewComponentId", _descriptor.Id),
|
||||
};
|
||||
if (index == 0)
|
||||
{
|
||||
return new KeyValuePair<string, object>("ViewComponentName", _descriptor.DisplayName);
|
||||
}
|
||||
else if (index == 1)
|
||||
{
|
||||
return new KeyValuePair<string, object>("ViewComponentId", _descriptor.Id);
|
||||
}
|
||||
throw new IndexOutOfRangeException(nameof(index));
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
|
||||
{
|
||||
for (int i = 0; i < Count; ++i)
|
||||
{
|
||||
yield return this[i];
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _descriptor.DisplayName;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
|
|||
return true;
|
||||
}
|
||||
|
||||
public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||
{
|
||||
Logged.Add(new LoggerData(logLevel, state));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue