Logging API changes

This commit is contained in:
Brennan 2015-03-04 20:43:09 -08:00
parent c290e897b0
commit f4ea1b82fa
36 changed files with 53 additions and 107 deletions

View File

@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
IOptions<AuthorizationOptions> options) IOptions<AuthorizationOptions> options)
{ {
_actionModelBuilder = actionModelBuilder; _actionModelBuilder = actionModelBuilder;
_logger = loggerFactory.Create<DefaultControllerModelBuilder>(); _logger = loggerFactory.CreateLogger<DefaultControllerModelBuilder>();
_authorizationOptions = options?.Options ?? new AuthorizationOptions(); _authorizationOptions = options?.Options ?? new AuthorizationOptions();
} }

View File

@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.Core
_applicationModelBuilder = applicationModelBuilder; _applicationModelBuilder = applicationModelBuilder;
_globalFilters = globalFilters.Filters; _globalFilters = globalFilters.Filters;
_conventions = optionsAccessor.Options.Conventions; _conventions = optionsAccessor.Options.Conventions;
_logger = loggerFactory.Create<ControllerActionDescriptorProvider>(); _logger = loggerFactory.CreateLogger<ControllerActionDescriptorProvider>();
} }
public int Order public int Order
@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Mvc.Core
{ {
foreach (var controller in applicationModel.Controllers) foreach (var controller in applicationModel.Controllers)
{ {
_logger.WriteVerbose(new ControllerModelValues(controller)); _logger.LogVerbose(new ControllerModelValues(controller));
} }
} }
return ControllerActionDescriptorBuilder.Build(applicationModel); return ControllerActionDescriptorBuilder.Build(applicationModel);

View File

@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Mvc.Core
public DefaultActionDescriptorsCollectionProvider(IServiceProvider serviceProvider, ILoggerFactory factory) public DefaultActionDescriptorsCollectionProvider(IServiceProvider serviceProvider, ILoggerFactory factory)
{ {
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_logger = factory.Create<DefaultActionDescriptorsCollectionProvider>(); _logger = factory.CreateLogger<DefaultActionDescriptorsCollectionProvider>();
} }
/// <summary> /// <summary>
@ -69,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.Core
{ {
foreach (var actionDescriptor in context.Results) foreach (var actionDescriptor in context.Results)
{ {
_logger.WriteVerbose(new ActionDescriptorValues(actionDescriptor)); _logger.LogVerbose(new ActionDescriptorValues(actionDescriptor));
} }
} }

View File

@ -31,7 +31,7 @@ namespace Microsoft.AspNet.Mvc.Core
_actionDescriptorsCollectionProvider = actionDescriptorsCollectionProvider; _actionDescriptorsCollectionProvider = actionDescriptorsCollectionProvider;
_decisionTreeProvider = decisionTreeProvider; _decisionTreeProvider = decisionTreeProvider;
_actionConstraintProviders = actionConstraintProviders.OrderBy(item => item.Order).ToArray(); _actionConstraintProviders = actionConstraintProviders.OrderBy(item => item.Order).ToArray();
_logger = loggerFactory.Create<DefaultActionSelector>(); _logger = loggerFactory.CreateLogger<DefaultActionSelector>();
} }
public Task<ActionDescriptor> SelectAsync([NotNull] RouteContext context) public Task<ActionDescriptor> SelectAsync([NotNull] RouteContext context)

View File

@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Mvc
ILoggerFactory loggerFactory) ILoggerFactory loggerFactory)
{ {
_assemblyProvider = assemblyProvider; _assemblyProvider = assemblyProvider;
_logger = loggerFactory.Create<DefaultControllerTypeProvider>(); _logger = loggerFactory.CreateLogger<DefaultControllerTypeProvider>();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -46,7 +46,7 @@ namespace Microsoft.AspNet.Mvc
{ {
foreach (var assembly in candidateAssemblies) foreach (var assembly in candidateAssemblies)
{ {
_logger.WriteVerbose(new AssemblyValues(assembly)); _logger.LogVerbose(new AssemblyValues(assembly));
} }
} }

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// <summary> /// <summary>
/// Logging representation of an <see cref="IActionConstraintMetadata"/>. /// Logging representation of an <see cref="IActionConstraintMetadata"/>.
/// </summary> /// </summary>
public class ActionConstraintValues : LoggerStructureBase public class ActionConstraintValues : ReflectionBasedLogValues
{ {
public ActionConstraintValues(IActionConstraintMetadata inner) public ActionConstraintValues(IActionConstraintMetadata inner)
{ {

View File

@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// Logging representation of the state of an <see cref="ActionDescriptor"/> or /// Logging representation of the state of an <see cref="ActionDescriptor"/> or
/// <see cref="ControllerActionDescriptor"/>. Logged during action discovery. /// <see cref="ControllerActionDescriptor"/>. Logged during action discovery.
/// </summary> /// </summary>
public class ActionDescriptorValues : LoggerStructureBase public class ActionDescriptorValues : ReflectionBasedLogValues
{ {
public ActionDescriptorValues([NotNull] ActionDescriptor inner) public ActionDescriptorValues([NotNull] ActionDescriptor inner)
{ {

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// Represents the state of an <see cref="ActionModel"/>. /// Represents the state of an <see cref="ActionModel"/>.
/// Logged as a substructure of <see cref="ControllerModelValues"/> /// Logged as a substructure of <see cref="ControllerModelValues"/>
/// </summary> /// </summary>
public class ActionModelValues : LoggerStructureBase public class ActionModelValues : ReflectionBasedLogValues
{ {
// note: omit the controller as this structure is nested inside the ControllerModelValues it belongs to // note: omit the controller as this structure is nested inside the ControllerModelValues it belongs to
public ActionModelValues(ActionModel inner) public ActionModelValues(ActionModel inner)

View File

@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// <summary> /// <summary>
/// Logging representation of an <see cref="ApiExplorerModel"/>. /// Logging representation of an <see cref="ApiExplorerModel"/>.
/// </summary> /// </summary>
public class ApiExplorerModelValues : LoggerStructureBase public class ApiExplorerModelValues : ReflectionBasedLogValues
{ {
public ApiExplorerModelValues(ApiExplorerModel inner) public ApiExplorerModelValues(ApiExplorerModel inner)
{ {

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// <summary> /// <summary>
/// Logging representation of the state of an <see cref="Assembly"/>. Logged during Assembly discovery in Startup. /// Logging representation of the state of an <see cref="Assembly"/>. Logged during Assembly discovery in Startup.
/// </summary> /// </summary>
public class AssemblyValues : LoggerStructureBase public class AssemblyValues : ReflectionBasedLogValues
{ {
public AssemblyValues([NotNull] Assembly inner) public AssemblyValues([NotNull] Assembly inner)
{ {

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// Logging representation of the state of a <see cref="AttributeRouteInfo"/>. Logged as a substructure of /// Logging representation of the state of a <see cref="AttributeRouteInfo"/>. Logged as a substructure of
/// <see cref="ActionDescriptorValues"/>. /// <see cref="ActionDescriptorValues"/>.
/// </summary> /// </summary>
public class AttributeRouteInfoValues : LoggerStructureBase public class AttributeRouteInfoValues : ReflectionBasedLogValues
{ {
public AttributeRouteInfoValues(AttributeRouteInfo inner) public AttributeRouteInfoValues(AttributeRouteInfo inner)
{ {

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// Logging representation of the state of a <see cref="AttributeRouteModel"/>. Logged as a substructure of /// Logging representation of the state of a <see cref="AttributeRouteModel"/>. Logged as a substructure of
/// <see cref="ControllerModelValues"/>. /// <see cref="ControllerModelValues"/>.
/// </summary> /// </summary>
public class AttributeRouteModelValues : LoggerStructureBase public class AttributeRouteModelValues : ReflectionBasedLogValues
{ {
public AttributeRouteModelValues(AttributeRouteModel inner) public AttributeRouteModelValues(AttributeRouteModel inner)
{ {

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// <summary> /// <summary>
/// Logging representation of the state of a <see cref="ControllerModel"/>. Logged during controller discovery. /// Logging representation of the state of a <see cref="ControllerModel"/>. Logged during controller discovery.
/// </summary> /// </summary>
public class ControllerModelValues : LoggerStructureBase public class ControllerModelValues : ReflectionBasedLogValues
{ {
public ControllerModelValues(ControllerModel inner) public ControllerModelValues(ControllerModel inner)
{ {

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// Logging representation of the state of a <see cref="FilterDescriptor"/>. Logged as a substructure of /// Logging representation of the state of a <see cref="FilterDescriptor"/>. Logged as a substructure of
/// <see cref="ActionDescriptorValues"/>. /// <see cref="ActionDescriptorValues"/>.
/// </summary> /// </summary>
public class FilterDescriptorValues : LoggerStructureBase public class FilterDescriptorValues : ReflectionBasedLogValues
{ {
public FilterDescriptorValues([NotNull] FilterDescriptor inner) public FilterDescriptorValues([NotNull] FilterDescriptor inner)
{ {

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// <see cref="FilterDescriptorValues"/>, and as a substructure of <see cref="ControllerModelValues"/> /// <see cref="FilterDescriptorValues"/>, and as a substructure of <see cref="ControllerModelValues"/>
/// and <see cref="ActionModelValues"/>. /// and <see cref="ActionModelValues"/>.
/// </summary> /// </summary>
public class FilterValues : LoggerStructureBase public class FilterValues : ReflectionBasedLogValues
{ {
public FilterValues(IFilter inner) public FilterValues(IFilter inner)
{ {

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Logging
{ {
public static void WriteValues([NotNull] this ILogger logger, object values) public static void WriteValues([NotNull] this ILogger logger, object values)
{ {
logger.Write( logger.Log(
logLevel: LogLevel.Verbose, logLevel: LogLevel.Verbose,
eventId: 0, eventId: 0,
state: values, state: values,

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// Logging representation of a <see cref="ParameterDescriptor"/>. Logged as a substructure of /// Logging representation of a <see cref="ParameterDescriptor"/>. Logged as a substructure of
/// <see cref="ActionDescriptorValues"/>. /// <see cref="ActionDescriptorValues"/>.
/// </summary> /// </summary>
public class ParameterDescriptorValues : LoggerStructureBase public class ParameterDescriptorValues : ReflectionBasedLogValues
{ {
public ParameterDescriptorValues([NotNull] ParameterDescriptor inner) public ParameterDescriptorValues([NotNull] ParameterDescriptor inner)
{ {

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// <see cref="ActionModelValues"/>, this contains the name, type, and /// <see cref="ActionModelValues"/>, this contains the name, type, and
/// binder metadata of the parameter. /// binder metadata of the parameter.
/// </summary> /// </summary>
public class ParameterModelValues : LoggerStructureBase public class ParameterModelValues : ReflectionBasedLogValues
{ {
public ParameterModelValues([NotNull] ParameterModel inner) public ParameterModelValues([NotNull] ParameterModel inner)
{ {

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// Logging representation of a <see cref="IRouteConstraintProvider"/>. Logged as a substructure of /// Logging representation of a <see cref="IRouteConstraintProvider"/>. Logged as a substructure of
/// <see cref="ControllerModelValues"/> /// <see cref="ControllerModelValues"/>
/// </summary> /// </summary>
public class RouteConstraintProviderValues : LoggerStructureBase public class RouteConstraintProviderValues : ReflectionBasedLogValues
{ {
public RouteConstraintProviderValues([NotNull] IRouteConstraintProvider inner) public RouteConstraintProviderValues([NotNull] IRouteConstraintProvider inner)
{ {

View File

@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Mvc.Logging
/// Logging representation of the state of a <see cref="RouteDataActionConstraint"/>. Logged as a substructure of /// Logging representation of the state of a <see cref="RouteDataActionConstraint"/>. Logged as a substructure of
/// <see cref="ActionDescriptorValues"/>. /// <see cref="ActionDescriptorValues"/>.
/// </summary> /// </summary>
public class RouteDataActionConstraintValues : LoggerStructureBase public class RouteDataActionConstraintValues : ReflectionBasedLogValues
{ {
public RouteDataActionConstraintValues([NotNull] RouteDataActionConstraint inner) public RouteDataActionConstraintValues([NotNull] RouteDataActionConstraint inner)
{ {

View File

@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Mvc
if (_logger == null) if (_logger == null)
{ {
var factory = context.RequestServices.GetRequiredService<ILoggerFactory>(); var factory = context.RequestServices.GetRequiredService<ILoggerFactory>();
_logger = factory.Create<MvcRouteHandler>(); _logger = factory.CreateLogger<MvcRouteHandler>();
} }
} }

View File

@ -36,8 +36,8 @@ namespace Microsoft.AspNet.Mvc.Routing
_actionDescriptorsCollectionProvider = actionDescriptorsCollectionProvider; _actionDescriptorsCollectionProvider = actionDescriptorsCollectionProvider;
_constraintResolver = constraintResolver; _constraintResolver = constraintResolver;
_routeLogger = loggerFactory.Create<InnerAttributeRoute>(); _routeLogger = loggerFactory.CreateLogger<InnerAttributeRoute>();
_constraintLogger = loggerFactory.Create(typeof(RouteConstraintMatcher).FullName); _constraintLogger = loggerFactory.CreateLogger(typeof(RouteConstraintMatcher).FullName);
// Force creation of the route to report issues on startup. // Force creation of the route to report issues on startup.
GetInnerRoute(); GetInnerRoute();

View File

@ -55,12 +55,12 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
attribute => PartiallyMatchedAttributes.Contains( attribute => PartiallyMatchedAttributes.Contains(
attribute, StringComparer.OrdinalIgnoreCase))); attribute, StringComparer.OrdinalIgnoreCase)));
logger.WriteWarning(new PartialModeMatchLoggerStructure<TMode>(uniqueId, viewPath, partialOnlyMatches)); logger.LogWarning(new PartialModeMatchLoggerStructure<TMode>(uniqueId, viewPath, partialOnlyMatches));
} }
if (logger.IsEnabled(LogLevel.Verbose) && !FullMatches.Any()) if (logger.IsEnabled(LogLevel.Verbose) && !FullMatches.Any())
{ {
logger.WriteVerbose("Skipping processing for {0} {1}", logger.LogVerbose("Skipping processing for {0} {1}",
tagHelper.GetType().GetTypeInfo().FullName, uniqueId); tagHelper.GetType().GetTypeInfo().FullName, uniqueId);
} }
} }

View File

@ -11,7 +11,7 @@ using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.TagHelpers.Internal namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
{ {
/// <summary> /// <summary>
/// An <see cref="ILoggerStructure"/> for log messages regarding <see cref="ITagHelper"/> instances that opt out of /// An <see cref="ILogValues"/> for log messages regarding <see cref="ITagHelper"/> instances that opt out of
/// processing due to missing attributes for one of several possible modes. /// processing due to missing attributes for one of several possible modes.
/// </summary> /// </summary>
public class PartialModeMatchLoggerStructure<TMode> : PartialModeMatchLoggerStructure public class PartialModeMatchLoggerStructure<TMode> : PartialModeMatchLoggerStructure

View File

@ -8,10 +8,10 @@ using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.TagHelpers.Internal namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
{ {
/// <summary> /// <summary>
/// An <see cref="ILoggerStructure"/> for log messages regarding <see cref="ITagHelper"/> instances that opt out of /// An <see cref="ILogValues"/> for log messages regarding <see cref="ITagHelper"/> instances that opt out of
/// processing due to missing attributes for one of several possible modes. /// processing due to missing attributes for one of several possible modes.
/// </summary> /// </summary>
public abstract class PartialModeMatchLoggerStructure : ILoggerStructure public abstract class PartialModeMatchLoggerStructure : ILogValues
{ {
private readonly IEnumerable<KeyValuePair<string, object>> _values; private readonly IEnumerable<KeyValuePair<string, object>> _values;

View File

@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Mvc
return NullDisposable.Instance; return NullDisposable.Instance;
} }
public void Write(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter) public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
{ {
} }

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Mvc
public LogLevel MinimumLevel { get; set; } public LogLevel MinimumLevel { get; set; }
public ILogger Create(string name) public ILogger CreateLogger(string name)
{ {
return NullLogger.Instance; return NullLogger.Instance;
} }

View File

@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Mvc
return NullDisposable.Instance; return NullDisposable.Instance;
} }
public void Write(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter) public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
{ {
_sink.Write(new WriteContext() _sink.Write(new WriteContext()
{ {

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Mvc
public LogLevel MinimumLevel { get; set; } public LogLevel MinimumLevel { get; set; }
public ILogger Create(string name) public ILogger CreateLogger(string name)
{ {
return new TestLogger(name, _sink); return new TestLogger(name, _sink);
} }

View File

@ -1710,8 +1710,8 @@ namespace Microsoft.AspNet.Mvc.Routing
new StubRouter(), new StubRouter(),
entries, entries,
Enumerable.Empty<AttributeRouteLinkGenerationEntry>(), Enumerable.Empty<AttributeRouteLinkGenerationEntry>(),
loggerFactory.Create<AttributeRoute>(), loggerFactory.CreateLogger<AttributeRoute>(),
loggerFactory.Create(typeof(RouteConstraintMatcher).FullName), loggerFactory.CreateLogger(typeof(RouteConstraintMatcher).FullName),
version: 1); version: 1);
} }

View File

@ -1,54 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc
{
public class NullLoggerFactory : ILoggerFactory
{
public LogLevel MinimumLevel { get; set; }
public static NullLoggerFactory Instance = new NullLoggerFactory();
public ILogger Create(string name)
{
return NullLogger.Instance;
}
public void AddProvider(ILoggerProvider provider)
{
}
}
public class NullLogger : ILogger
{
public static NullLogger Instance = new NullLogger();
public IDisposable BeginScope(object state)
{
return NullDisposable.Instance;
}
public void Write(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
{
}
public bool IsEnabled(LogLevel logLevel)
{
return false;
}
}
public class NullDisposable : IDisposable
{
public static NullDisposable Instance = new NullDisposable();
public void Dispose()
{
// intentionally does nothing
}
}
}

View File

@ -69,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
} }
public ILogger Create(string name) public ILogger CreateLogger(string name)
{ {
return new TestLogger(); return new TestLogger();
} }
@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
return new TestDisposable(); return new TestDisposable();
} }
public void Write(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter) public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
{ {
} }

View File

@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
modeMatchResult.LogDetails(logger, tagHelper.Object, uniqueId, viewPath); modeMatchResult.LogDetails(logger, tagHelper.Object, uniqueId, viewPath);
// Assert // Assert
Mock.Get(logger).Verify(l => l.Write( Mock.Get(logger).Verify(l => l.Log(
LogLevel.Verbose, LogLevel.Verbose,
It.IsAny<int>(), It.IsAny<int>(),
It.IsAny<object>(), It.IsAny<object>(),
@ -51,13 +51,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
modeMatchResult.LogDetails(logger, tagHelper.Object, uniqueId, viewPath); modeMatchResult.LogDetails(logger, tagHelper.Object, uniqueId, viewPath);
// Assert // Assert
Mock.Get(logger).Verify(l => l.Write( Mock.Get(logger).Verify(l => l.Log(
LogLevel.Warning, LogLevel.Warning,
It.IsAny<int>(), It.IsAny<int>(),
It.IsAny<object>(), It.IsAny<object>(),
It.IsAny<Exception>(), It.IsAny<Exception>(),
It.IsAny<Func<object, Exception, string>>()), Times.Never); It.IsAny<Func<object, Exception, string>>()), Times.Never);
Mock.Get(logger).Verify(l => l.Write( Mock.Get(logger).Verify(l => l.Log(
LogLevel.Verbose, LogLevel.Verbose,
It.IsAny<int>(), It.IsAny<int>(),
It.IsAny<object>(), It.IsAny<object>(),
@ -82,13 +82,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
modeMatchResult.LogDetails(logger, tagHelper.Object, uniqueId, viewPath); modeMatchResult.LogDetails(logger, tagHelper.Object, uniqueId, viewPath);
// Assert // Assert
Mock.Get(logger).Verify(l => l.Write( Mock.Get(logger).Verify(l => l.Log(
LogLevel.Warning, LogLevel.Warning,
It.IsAny<int>(), It.IsAny<int>(),
It.IsAny<object>(), It.IsAny<object>(),
It.IsAny<Exception>(), It.IsAny<Exception>(),
It.IsAny<Func<object, Exception, string>>()), Times.Once); It.IsAny<Func<object, Exception, string>>()), Times.Once);
Mock.Get(logger).Verify(l => l.Write( Mock.Get(logger).Verify(l => l.Log(
LogLevel.Verbose, LogLevel.Verbose,
It.IsAny<int>(), It.IsAny<int>(),
It.IsAny<object>(), It.IsAny<object>(),
@ -113,13 +113,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
modeMatchResult.LogDetails(logger, tagHelper.Object, uniqueId, viewPath); modeMatchResult.LogDetails(logger, tagHelper.Object, uniqueId, viewPath);
// Assert // Assert
Mock.Get(logger).Verify(l => l.Write( Mock.Get(logger).Verify(l => l.Log(
LogLevel.Warning, LogLevel.Warning,
It.IsAny<int>(), It.IsAny<int>(),
It.IsAny<object>(), It.IsAny<object>(),
It.IsAny<Exception>(), It.IsAny<Exception>(),
It.IsAny<Func<object, Exception, string>>()), Times.Never); It.IsAny<Func<object, Exception, string>>()), Times.Never);
Mock.Get(logger).Verify(l => l.Write( Mock.Get(logger).Verify(l => l.Log(
LogLevel.Verbose, LogLevel.Verbose,
It.IsAny<int>(), It.IsAny<int>(),
It.IsAny<object>(), It.IsAny<object>(),

View File

@ -260,9 +260,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
var loggerData0 = (PartialModeMatchLoggerStructure)logger.Logged[0].State; var loggerData0 = (PartialModeMatchLoggerStructure)logger.Logged[0].State;
Assert.Equal(LogLevel.Verbose, logger.Logged[1].LogLevel); Assert.Equal(LogLevel.Verbose, logger.Logged[1].LogLevel);
Assert.IsAssignableFrom<ILoggerStructure>(logger.Logged[1].State); Assert.IsAssignableFrom<ILogValues>(logger.Logged[1].State);
Assert.StartsWith("Skipping processing for Microsoft.AspNet.Mvc.TagHelpers.ScriptTagHelper", Assert.StartsWith("Skipping processing for Microsoft.AspNet.Mvc.TagHelpers.ScriptTagHelper",
((ILoggerStructure)logger.Logged[1].State).Format()); ((ILogValues)logger.Logged[1].State).Format());
} }
[Fact] [Fact]
@ -313,9 +313,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Single(logger.Logged); Assert.Single(logger.Logged);
Assert.Equal(LogLevel.Verbose, logger.Logged[0].LogLevel); Assert.Equal(LogLevel.Verbose, logger.Logged[0].LogLevel);
Assert.IsAssignableFrom<ILoggerStructure>(logger.Logged[0].State); Assert.IsAssignableFrom<ILogValues>(logger.Logged[0].State);
Assert.StartsWith("Skipping processing for Microsoft.AspNet.Mvc.TagHelpers.ScriptTagHelper", Assert.StartsWith("Skipping processing for Microsoft.AspNet.Mvc.TagHelpers.ScriptTagHelper",
((ILoggerStructure)logger.Logged[0].State).Format()); ((ILogValues)logger.Logged[0].State).Format());
} }
[Fact] [Fact]

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
return true; return true;
} }
public void Write(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter) public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
{ {
Logged.Add(new LoggerData(logLevel, state)); Logged.Add(new LoggerData(logLevel, state));
} }

View File

@ -12,7 +12,7 @@ namespace ModelBindingWebSite
public DefaultCalculator(ILoggerFactory loggerFactory) public DefaultCalculator(ILoggerFactory loggerFactory)
{ {
_logger = loggerFactory.Create(typeof(DefaultCalculator).FullName); _logger = loggerFactory.CreateLogger(typeof(DefaultCalculator).FullName);
} }
public int Operation(char @operator, int left, int right) public int Operation(char @operator, int left, int right)
@ -24,7 +24,7 @@ namespace ModelBindingWebSite
case '*': return left * right; case '*': return left * right;
case '/': return left / right; case '/': return left / right;
default: default:
_logger.WriteError("Unrecognized operator:" + @operator); _logger.LogError("Unrecognized operator:" + @operator);
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
} }