[Fixes #3755] Added logging for view compilation
This commit is contained in:
parent
c68f742dd0
commit
0bb772a815
|
|
@ -3,12 +3,15 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNet.Diagnostics;
|
using Microsoft.AspNet.Diagnostics;
|
||||||
using Microsoft.AspNet.FileProviders;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
using Microsoft.AspNet.Mvc.Logging;
|
||||||
using Microsoft.AspNet.Razor;
|
using Microsoft.AspNet.Razor;
|
||||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
|
|
@ -21,6 +24,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
private readonly ICompilationService _compilationService;
|
private readonly ICompilationService _compilationService;
|
||||||
private readonly IMvcRazorHost _razorHost;
|
private readonly IMvcRazorHost _razorHost;
|
||||||
private readonly IFileProvider _fileProvider;
|
private readonly IFileProvider _fileProvider;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instantiates a new instance of the <see cref="RazorCompilationService"/> class.
|
/// Instantiates a new instance of the <see cref="RazorCompilationService"/> class.
|
||||||
|
|
@ -31,11 +35,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
public RazorCompilationService(
|
public RazorCompilationService(
|
||||||
ICompilationService compilationService,
|
ICompilationService compilationService,
|
||||||
IMvcRazorHost razorHost,
|
IMvcRazorHost razorHost,
|
||||||
IRazorViewEngineFileProviderAccessor fileProviderAccessor)
|
IRazorViewEngineFileProviderAccessor fileProviderAccessor,
|
||||||
|
ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_compilationService = compilationService;
|
_compilationService = compilationService;
|
||||||
_razorHost = razorHost;
|
_razorHost = razorHost;
|
||||||
_fileProvider = fileProviderAccessor.FileProvider;
|
_fileProvider = fileProviderAccessor.FileProvider;
|
||||||
|
_logger = loggerFactory.CreateLogger<RazorCompilationService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
@ -49,7 +55,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
GeneratorResults results;
|
GeneratorResults results;
|
||||||
using (var inputStream = file.FileInfo.CreateReadStream())
|
using (var inputStream = file.FileInfo.CreateReadStream())
|
||||||
{
|
{
|
||||||
|
_logger.RazorFileToCodeCompilationStart(file.RelativePath);
|
||||||
|
|
||||||
|
var startTimestamp = _logger.IsEnabled(LogLevel.Debug) ? Stopwatch.GetTimestamp() : 0;
|
||||||
|
|
||||||
results = GenerateCode(file.RelativePath, inputStream);
|
results = GenerateCode(file.RelativePath, inputStream);
|
||||||
|
|
||||||
|
_logger.RazorFileToCodeCompilationEnd(file.RelativePath, startTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!results.Success)
|
if (!results.Success)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ using System.Runtime.Loader;
|
||||||
#endif
|
#endif
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
using Microsoft.AspNet.FileProviders;
|
using Microsoft.AspNet.FileProviders;
|
||||||
|
using Microsoft.AspNet.Mvc.Logging;
|
||||||
using Microsoft.AspNet.Mvc.Razor.Internal;
|
using Microsoft.AspNet.Mvc.Razor.Internal;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
|
|
@ -22,6 +23,7 @@ using Microsoft.Dnx.Compilation.CSharp;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.AspNet.Diagnostics;
|
using Microsoft.AspNet.Diagnostics;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
{
|
{
|
||||||
|
|
@ -42,6 +44,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
private readonly Action<RoslynCompilationContext> _compilationCallback;
|
private readonly Action<RoslynCompilationContext> _compilationCallback;
|
||||||
private readonly CSharpParseOptions _parseOptions;
|
private readonly CSharpParseOptions _parseOptions;
|
||||||
private readonly CSharpCompilationOptions _compilationOptions;
|
private readonly CSharpCompilationOptions _compilationOptions;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
#if DOTNET5_5
|
#if DOTNET5_5
|
||||||
private readonly RazorLoadContext _razorLoadContext;
|
private readonly RazorLoadContext _razorLoadContext;
|
||||||
|
|
@ -60,7 +63,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
Extensions.CompilationAbstractions.ILibraryExporter libraryExporter,
|
Extensions.CompilationAbstractions.ILibraryExporter libraryExporter,
|
||||||
IMvcRazorHost host,
|
IMvcRazorHost host,
|
||||||
IOptions<RazorViewEngineOptions> optionsAccessor,
|
IOptions<RazorViewEngineOptions> optionsAccessor,
|
||||||
IRazorViewEngineFileProviderAccessor fileProviderAccessor)
|
IRazorViewEngineFileProviderAccessor fileProviderAccessor,
|
||||||
|
ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_environment = environment;
|
_environment = environment;
|
||||||
_libraryExporter = libraryExporter;
|
_libraryExporter = libraryExporter;
|
||||||
|
|
@ -70,6 +74,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
_compilationCallback = optionsAccessor.Value.CompilationCallback;
|
_compilationCallback = optionsAccessor.Value.CompilationCallback;
|
||||||
_parseOptions = optionsAccessor.Value.ParseOptions;
|
_parseOptions = optionsAccessor.Value.ParseOptions;
|
||||||
_compilationOptions = optionsAccessor.Value.CompilationOptions;
|
_compilationOptions = optionsAccessor.Value.CompilationOptions;
|
||||||
|
_logger = loggerFactory.CreateLogger<RoslynCompilationService>();
|
||||||
|
|
||||||
#if DOTNET5_5
|
#if DOTNET5_5
|
||||||
_razorLoadContext = new RazorLoadContext();
|
_razorLoadContext = new RazorLoadContext();
|
||||||
|
|
@ -89,6 +94,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
throw new ArgumentNullException(nameof(compilationContent));
|
throw new ArgumentNullException(nameof(compilationContent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_logger.GeneratedCodeToAssemblyCompilationStart(fileInfo.RelativePath);
|
||||||
|
|
||||||
|
var startTimestamp = _logger.IsEnabled(LogLevel.Debug) ? Stopwatch.GetTimestamp() : 0;
|
||||||
|
|
||||||
var assemblyName = Path.GetRandomFileName();
|
var assemblyName = Path.GetRandomFileName();
|
||||||
|
|
||||||
var syntaxTree = SyntaxTreeGenerator.Generate(
|
var syntaxTree = SyntaxTreeGenerator.Generate(
|
||||||
|
|
@ -150,6 +159,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
var type = assembly.GetExportedTypes()
|
var type = assembly.GetExportedTypes()
|
||||||
.First(t => t.Name.StartsWith(_classPrefix, StringComparison.Ordinal));
|
.First(t => t.Name.StartsWith(_classPrefix, StringComparison.Ordinal));
|
||||||
|
|
||||||
|
_logger.GeneratedCodeToAssemblyCompilationEnd(fileInfo.RelativePath, startTimestamp);
|
||||||
|
|
||||||
return new CompilationResult(type);
|
return new CompilationResult(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc.Logging
|
||||||
|
{
|
||||||
|
public static class RazorCompilationServiceLoggerExtensions
|
||||||
|
{
|
||||||
|
private static readonly double TimestampToTicks = Stopwatch.Frequency / 10000000.0;
|
||||||
|
private static readonly Action<ILogger, string, Exception> _razorFileToCodeCompilationStart;
|
||||||
|
private static readonly Action<ILogger, string, double, Exception> _razorFileToCodeCompilationEnd;
|
||||||
|
|
||||||
|
static RazorCompilationServiceLoggerExtensions()
|
||||||
|
{
|
||||||
|
_razorFileToCodeCompilationStart = LoggerMessage.Define<string>(
|
||||||
|
LogLevel.Debug,
|
||||||
|
1,
|
||||||
|
"Code generation for the Razor file at '{FilePath}' started.");
|
||||||
|
|
||||||
|
_razorFileToCodeCompilationEnd = LoggerMessage.Define<string, double>(
|
||||||
|
LogLevel.Debug,
|
||||||
|
2,
|
||||||
|
"Code generation for the Razor file at '{FilePath}' completed in {ElapsedMilliseconds}ms.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RazorFileToCodeCompilationStart(this ILogger logger, string filePath)
|
||||||
|
{
|
||||||
|
_razorFileToCodeCompilationStart(logger, filePath, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RazorFileToCodeCompilationEnd(this ILogger logger, string filePath, long startTimestamp)
|
||||||
|
{
|
||||||
|
// Don't log if logging wasn't enabled at start of request as time will be wildly wrong.
|
||||||
|
if (startTimestamp != 0)
|
||||||
|
{
|
||||||
|
var currentTimestamp = Stopwatch.GetTimestamp();
|
||||||
|
var elapsed = new TimeSpan((long)(TimestampToTicks * (currentTimestamp - startTimestamp)));
|
||||||
|
_razorFileToCodeCompilationEnd(logger, filePath, elapsed.TotalMilliseconds, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright (c) .NET Foundation. 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.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc.Logging
|
||||||
|
{
|
||||||
|
public static class RazorViewEngineLoggerExtensions
|
||||||
|
{
|
||||||
|
private static readonly Action<ILogger, string, string, Exception> _viewLookupCacheMiss;
|
||||||
|
private static readonly Action<ILogger, string, string, Exception> _viewLookupCacheHit;
|
||||||
|
|
||||||
|
static RazorViewEngineLoggerExtensions()
|
||||||
|
{
|
||||||
|
_viewLookupCacheMiss = LoggerMessage.Define<string, string>(
|
||||||
|
LogLevel.Debug,
|
||||||
|
1,
|
||||||
|
"View lookup cache miss for view '{ViewName}' in controller '{ControllerName}'.");
|
||||||
|
|
||||||
|
_viewLookupCacheHit = LoggerMessage.Define<string, string>(
|
||||||
|
LogLevel.Debug,
|
||||||
|
2,
|
||||||
|
"View lookup cache hit for view '{ViewName}' in controller '{ControllerName}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ViewLookupCacheMiss(this ILogger logger, string viewName, string controllerName)
|
||||||
|
{
|
||||||
|
_viewLookupCacheMiss(logger, viewName, controllerName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ViewLookupCacheHit(this ILogger logger, string viewName, string controllerName)
|
||||||
|
{
|
||||||
|
_viewLookupCacheHit(logger, viewName, controllerName, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Mvc.Logging
|
||||||
|
{
|
||||||
|
public static class RoslynCompilationServiceLoggerExtensions
|
||||||
|
{
|
||||||
|
private static readonly double TimestampToTicks = Stopwatch.Frequency / 10000000.0;
|
||||||
|
private static readonly Action<ILogger, string, Exception> _generatedCodeToAssemblyCompilationStart;
|
||||||
|
private static readonly Action<ILogger, string, double, Exception> _generatedCodeToAssemblyCompilationEnd;
|
||||||
|
|
||||||
|
static RoslynCompilationServiceLoggerExtensions()
|
||||||
|
{
|
||||||
|
_generatedCodeToAssemblyCompilationStart = LoggerMessage.Define<string>(
|
||||||
|
LogLevel.Debug,
|
||||||
|
1,
|
||||||
|
"Compilation of the generated code for the Razor file at '{FilePath}' started.");
|
||||||
|
|
||||||
|
_generatedCodeToAssemblyCompilationEnd = LoggerMessage.Define<string, double>(
|
||||||
|
LogLevel.Debug,
|
||||||
|
2,
|
||||||
|
"Compilation of the generated code for the Razor file at '{FilePath}' completed in {ElapsedMilliseconds}ms.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GeneratedCodeToAssemblyCompilationStart(this ILogger logger, string filePath)
|
||||||
|
{
|
||||||
|
_generatedCodeToAssemblyCompilationStart(logger, filePath, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GeneratedCodeToAssemblyCompilationEnd(this ILogger logger, string filePath, long startTimestamp)
|
||||||
|
{
|
||||||
|
// Don't log if logging wasn't enabled at start of request as time will be wildly wrong.
|
||||||
|
if (startTimestamp != 0)
|
||||||
|
{
|
||||||
|
var currentTimestamp = Stopwatch.GetTimestamp();
|
||||||
|
var elapsed = new TimeSpan((long)(TimestampToTicks * (currentTimestamp - startTimestamp)));
|
||||||
|
_generatedCodeToAssemblyCompilationEnd(logger, filePath, elapsed.TotalMilliseconds, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,9 +7,11 @@ using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
|
using Microsoft.AspNet.Mvc.Logging;
|
||||||
using Microsoft.AspNet.Mvc.Routing;
|
using Microsoft.AspNet.Mvc.Routing;
|
||||||
using Microsoft.AspNet.Mvc.ViewEngines;
|
using Microsoft.AspNet.Mvc.ViewEngines;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
|
|
@ -35,6 +37,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
private readonly IList<IViewLocationExpander> _viewLocationExpanders;
|
private readonly IList<IViewLocationExpander> _viewLocationExpanders;
|
||||||
private readonly IRazorPageActivator _pageActivator;
|
private readonly IRazorPageActivator _pageActivator;
|
||||||
private readonly HtmlEncoder _htmlEncoder;
|
private readonly HtmlEncoder _htmlEncoder;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RazorViewEngine" />.
|
/// Initializes a new instance of the <see cref="RazorViewEngine" />.
|
||||||
|
|
@ -43,12 +46,14 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
IRazorPageFactoryProvider pageFactory,
|
IRazorPageFactoryProvider pageFactory,
|
||||||
IRazorPageActivator pageActivator,
|
IRazorPageActivator pageActivator,
|
||||||
HtmlEncoder htmlEncoder,
|
HtmlEncoder htmlEncoder,
|
||||||
IOptions<RazorViewEngineOptions> optionsAccessor)
|
IOptions<RazorViewEngineOptions> optionsAccessor,
|
||||||
|
ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_pageFactory = pageFactory;
|
_pageFactory = pageFactory;
|
||||||
_pageActivator = pageActivator;
|
_pageActivator = pageActivator;
|
||||||
_viewLocationExpanders = optionsAccessor.Value.ViewLocationExpanders;
|
_viewLocationExpanders = optionsAccessor.Value.ViewLocationExpanders;
|
||||||
_htmlEncoder = htmlEncoder;
|
_htmlEncoder = htmlEncoder;
|
||||||
|
_logger = loggerFactory.CreateLogger<RazorViewEngine>();
|
||||||
ViewLookupCache = new MemoryCache(new MemoryCacheOptions
|
ViewLookupCache = new MemoryCache(new MemoryCacheOptions
|
||||||
{
|
{
|
||||||
CompactOnMemoryPressure = false
|
CompactOnMemoryPressure = false
|
||||||
|
|
@ -341,8 +346,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
ViewLocationCacheResult cacheResult;
|
ViewLocationCacheResult cacheResult;
|
||||||
if (!ViewLookupCache.TryGetValue(cacheKey, out cacheResult))
|
if (!ViewLookupCache.TryGetValue(cacheKey, out cacheResult))
|
||||||
{
|
{
|
||||||
|
_logger.ViewLookupCacheMiss(cacheKey.ViewName, cacheKey.ControllerName);
|
||||||
cacheResult = OnCacheMiss(expanderContext, cacheKey);
|
cacheResult = OnCacheMiss(expanderContext, cacheKey);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.ViewLookupCacheHit(cacheKey.ViewName, cacheKey.ControllerName);
|
||||||
|
}
|
||||||
|
|
||||||
return cacheResult;
|
return cacheResult;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNet.Razor.Chunks;
|
||||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||||
using Microsoft.AspNet.Razor.Compilation.TagHelpers;
|
using Microsoft.AspNet.Razor.Compilation.TagHelpers;
|
||||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
@ -38,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
compiler.Setup(c => c.Compile(relativeFileInfo, It.IsAny<string>()))
|
compiler.Setup(c => c.Compile(relativeFileInfo, It.IsAny<string>()))
|
||||||
.Returns(new CompilationResult(typeof(RazorCompilationServiceTest)));
|
.Returns(new CompilationResult(typeof(RazorCompilationServiceTest)));
|
||||||
|
|
||||||
var razorService = new RazorCompilationService(compiler.Object, host.Object, GetFileProviderAccessor());
|
var razorService = new RazorCompilationService(compiler.Object, host.Object, GetFileProviderAccessor(), NullLoggerFactory.Instance);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
razorService.Compile(relativeFileInfo);
|
razorService.Compile(relativeFileInfo);
|
||||||
|
|
@ -70,7 +71,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
|
|
||||||
var compiler = new Mock<ICompilationService>(MockBehavior.Strict);
|
var compiler = new Mock<ICompilationService>(MockBehavior.Strict);
|
||||||
var relativeFileInfo = new RelativeFileInfo(fileInfo.Object, @"Views\index\home.cshtml");
|
var relativeFileInfo = new RelativeFileInfo(fileInfo.Object, @"Views\index\home.cshtml");
|
||||||
var razorService = new RazorCompilationService(compiler.Object, host.Object, GetFileProviderAccessor());
|
var razorService = new RazorCompilationService(compiler.Object, host.Object, GetFileProviderAccessor(), NullLoggerFactory.Instance);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = razorService.Compile(relativeFileInfo);
|
var result = razorService.Compile(relativeFileInfo);
|
||||||
|
|
@ -111,7 +112,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
compiler.Setup(c => c.Compile(relativeFileInfo, code))
|
compiler.Setup(c => c.Compile(relativeFileInfo, code))
|
||||||
.Returns(compilationResult)
|
.Returns(compilationResult)
|
||||||
.Verifiable();
|
.Verifiable();
|
||||||
var razorService = new RazorCompilationService(compiler.Object, host.Object, GetFileProviderAccessor());
|
var razorService = new RazorCompilationService(compiler.Object, host.Object, GetFileProviderAccessor(), NullLoggerFactory.Instance);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = razorService.Compile(relativeFileInfo);
|
var result = razorService.Compile(relativeFileInfo);
|
||||||
|
|
@ -136,7 +137,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation
|
||||||
var razorService = new RazorCompilationService(
|
var razorService = new RazorCompilationService(
|
||||||
Mock.Of<ICompilationService>(),
|
Mock.Of<ICompilationService>(),
|
||||||
Mock.Of<IMvcRazorHost>(),
|
Mock.Of<IMvcRazorHost>(),
|
||||||
GetFileProviderAccessor(fileProvider));
|
GetFileProviderAccessor(fileProvider),
|
||||||
|
NullLoggerFactory.Instance);
|
||||||
var errors = new[]
|
var errors = new[]
|
||||||
{
|
{
|
||||||
new RazorError("message-1", new SourceLocation(1, 2, 17), length: 1),
|
new RazorError("message-1", new SourceLocation(1, 2, 17), length: 1),
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using Microsoft.AspNet.FileProviders;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.Text;
|
using Microsoft.CodeAnalysis.Text;
|
||||||
using Microsoft.Extensions.CompilationAbstractions;
|
using Microsoft.Extensions.CompilationAbstractions;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
@ -34,7 +35,8 @@ public class MyTestType {}";
|
||||||
libraryExporter,
|
libraryExporter,
|
||||||
mvcRazorHost.Object,
|
mvcRazorHost.Object,
|
||||||
GetOptions(),
|
GetOptions(),
|
||||||
GetFileProviderAccessor());
|
GetFileProviderAccessor(),
|
||||||
|
NullLoggerFactory.Instance);
|
||||||
var relativeFileInfo = new RelativeFileInfo(
|
var relativeFileInfo = new RelativeFileInfo(
|
||||||
new TestFileInfo { PhysicalPath = "SomePath" },
|
new TestFileInfo { PhysicalPath = "SomePath" },
|
||||||
"some-relative-path");
|
"some-relative-path");
|
||||||
|
|
@ -66,7 +68,8 @@ this should fail";
|
||||||
libraryExporter,
|
libraryExporter,
|
||||||
mvcRazorHost,
|
mvcRazorHost,
|
||||||
GetOptions(),
|
GetOptions(),
|
||||||
GetFileProviderAccessor(fileProvider));
|
GetFileProviderAccessor(fileProvider),
|
||||||
|
NullLoggerFactory.Instance);
|
||||||
var relativeFileInfo = new RelativeFileInfo(fileInfo, "some-relative-path");
|
var relativeFileInfo = new RelativeFileInfo(fileInfo, "some-relative-path");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -95,7 +98,8 @@ this should fail";
|
||||||
libraryExporter,
|
libraryExporter,
|
||||||
mvcRazorHost,
|
mvcRazorHost,
|
||||||
GetOptions(),
|
GetOptions(),
|
||||||
GetFileProviderAccessor());
|
GetFileProviderAccessor(),
|
||||||
|
NullLoggerFactory.Instance);
|
||||||
var relativeFileInfo = new RelativeFileInfo(
|
var relativeFileInfo = new RelativeFileInfo(
|
||||||
new TestFileInfo { Content = fileContent },
|
new TestFileInfo { Content = fileContent },
|
||||||
"some-relative-path");
|
"some-relative-path");
|
||||||
|
|
@ -135,7 +139,8 @@ this should fail";
|
||||||
libraryExporter,
|
libraryExporter,
|
||||||
mvcRazorHost,
|
mvcRazorHost,
|
||||||
GetOptions(),
|
GetOptions(),
|
||||||
GetFileProviderAccessor(fileProvider));
|
GetFileProviderAccessor(fileProvider),
|
||||||
|
NullLoggerFactory.Instance);
|
||||||
|
|
||||||
var relativeFileInfo = new RelativeFileInfo(mockFileInfo.Object, path);
|
var relativeFileInfo = new RelativeFileInfo(mockFileInfo.Object, path);
|
||||||
|
|
||||||
|
|
@ -175,7 +180,8 @@ public class MyNonCustomDefinedClass {}
|
||||||
libraryExporter,
|
libraryExporter,
|
||||||
mvcRazorHost.Object,
|
mvcRazorHost.Object,
|
||||||
options,
|
options,
|
||||||
GetFileProviderAccessor());
|
GetFileProviderAccessor(),
|
||||||
|
NullLoggerFactory.Instance);
|
||||||
var relativeFileInfo = new RelativeFileInfo(
|
var relativeFileInfo = new RelativeFileInfo(
|
||||||
new TestFileInfo { PhysicalPath = "SomePath" },
|
new TestFileInfo { PhysicalPath = "SomePath" },
|
||||||
"some-relative-path");
|
"some-relative-path");
|
||||||
|
|
@ -206,7 +212,8 @@ public class NotRazorPrefixType {}";
|
||||||
libraryExporter,
|
libraryExporter,
|
||||||
mvcRazorHost.Object,
|
mvcRazorHost.Object,
|
||||||
GetOptions(),
|
GetOptions(),
|
||||||
GetFileProviderAccessor());
|
GetFileProviderAccessor(),
|
||||||
|
NullLoggerFactory.Instance);
|
||||||
|
|
||||||
var relativeFileInfo = new RelativeFileInfo(
|
var relativeFileInfo = new RelativeFileInfo(
|
||||||
new TestFileInfo { PhysicalPath = "SomePath" },
|
new TestFileInfo { PhysicalPath = "SomePath" },
|
||||||
|
|
@ -238,7 +245,8 @@ public class NotRazorPrefixType {}";
|
||||||
CompilationServices.Default.LibraryExporter,
|
CompilationServices.Default.LibraryExporter,
|
||||||
Mock.Of<IMvcRazorHost>(),
|
Mock.Of<IMvcRazorHost>(),
|
||||||
optionsAccessor.Object,
|
optionsAccessor.Object,
|
||||||
GetFileProviderAccessor(fileProvider));
|
GetFileProviderAccessor(fileProvider),
|
||||||
|
NullLoggerFactory.Instance);
|
||||||
|
|
||||||
var assemblyName = "random-assembly-name";
|
var assemblyName = "random-assembly-name";
|
||||||
|
|
||||||
|
|
@ -330,7 +338,8 @@ public class NotRazorPrefixType {}";
|
||||||
libraryExporter,
|
libraryExporter,
|
||||||
mvcRazorHost.Object,
|
mvcRazorHost.Object,
|
||||||
GetOptions(callback: c => usedCompilation = c),
|
GetOptions(callback: c => usedCompilation = c),
|
||||||
GetFileProviderAccessor());
|
GetFileProviderAccessor(),
|
||||||
|
NullLoggerFactory.Instance);
|
||||||
|
|
||||||
var relativeFileInfo = new RelativeFileInfo(
|
var relativeFileInfo = new RelativeFileInfo(
|
||||||
new TestFileInfo { PhysicalPath = "SomePath" },
|
new TestFileInfo { PhysicalPath = "SomePath" },
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ using Microsoft.AspNet.Mvc.ViewEngines;
|
||||||
using Microsoft.AspNet.Routing;
|
using Microsoft.AspNet.Routing;
|
||||||
using Microsoft.AspNet.Testing;
|
using Microsoft.AspNet.Testing;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
using Microsoft.Extensions.WebEncoders.Testing;
|
using Microsoft.Extensions.WebEncoders.Testing;
|
||||||
|
|
@ -1806,7 +1807,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
||||||
public TestableRazorViewEngine(
|
public TestableRazorViewEngine(
|
||||||
IRazorPageFactoryProvider pageFactory,
|
IRazorPageFactoryProvider pageFactory,
|
||||||
IOptions<RazorViewEngineOptions> optionsAccessor)
|
IOptions<RazorViewEngineOptions> optionsAccessor)
|
||||||
: base(pageFactory, Mock.Of<IRazorPageActivator>(), new HtmlTestEncoder(), optionsAccessor)
|
: base(pageFactory, Mock.Of<IRazorPageActivator>(), new HtmlTestEncoder(), optionsAccessor, NullLoggerFactory.Instance)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
"Microsoft.Dnx.Runtime": "1.0.0-*",
|
"Microsoft.Dnx.Runtime": "1.0.0-*",
|
||||||
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
"Microsoft.Extensions.DependencyInjection": "1.0.0-*",
|
||||||
"Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*",
|
"Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*",
|
||||||
|
"Microsoft.Extensions.Logging.Testing": "1.0.0-*",
|
||||||
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
"xunit.runner.aspnet": "2.0.0-aspnet-*"
|
||||||
},
|
},
|
||||||
"commands": {
|
"commands": {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using System.Text;
|
||||||
using Microsoft.AspNet.Mvc.Razor;
|
using Microsoft.AspNet.Mvc.Razor;
|
||||||
using Microsoft.AspNet.Mvc.Razor.Compilation;
|
using Microsoft.AspNet.Mvc.Razor.Compilation;
|
||||||
using Microsoft.AspNet.Razor.CodeGenerators;
|
using Microsoft.AspNet.Razor.CodeGenerators;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace RazorPageExecutionInstrumentationWebSite
|
namespace RazorPageExecutionInstrumentationWebSite
|
||||||
{
|
{
|
||||||
|
|
@ -14,8 +15,9 @@ namespace RazorPageExecutionInstrumentationWebSite
|
||||||
public TestRazorCompilationService(
|
public TestRazorCompilationService(
|
||||||
ICompilationService compilationService,
|
ICompilationService compilationService,
|
||||||
IMvcRazorHost razorHost,
|
IMvcRazorHost razorHost,
|
||||||
IRazorViewEngineFileProviderAccessor fileProviderAccessor)
|
IRazorViewEngineFileProviderAccessor fileProviderAccessor,
|
||||||
: base(compilationService, razorHost, fileProviderAccessor)
|
ILoggerFactory loggerFactory)
|
||||||
|
: base(compilationService, razorHost, fileProviderAccessor, loggerFactory)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue