From 173f00fda798fed6adb658bb4ca413daa251acc7 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Tue, 20 Oct 2015 11:29:15 -0700 Subject: [PATCH] Update to use DiagnosticSource --- Mvc.NoFun.sln | 2 +- Mvc.sln | 2 +- .../Controllers/ControllerActionInvoker.cs | 12 +++--- .../ControllerActionInvokerProvider.cs | 12 +++--- .../Controllers/FilterActionInvoker.cs | 41 +++++++------------ .../Infrastructure/MvcRouteHandler.cs | 26 ++++-------- src/Microsoft.AspNet.Mvc.Core/project.json | 2 +- .../ViewFeatures/PartialViewResultExecutor.cs | 23 ++++------- .../ViewFeatures/ViewExecutor.cs | 34 +++++++-------- .../ViewFeatures/ViewResultExecutor.cs | 22 ++++------ .../ControllerActionInvokerTest.cs | 18 ++++---- .../Infrastructure/MvcRouteHandlerTests.cs | 32 +++++++-------- .../project.json | 4 +- .../IProxyActionContext.cs | 0 .../IProxyActionDescriptor.cs | 0 .../IProxyActionResult.cs | 0 .../IProxyHttpContext.cs | 0 .../IProxyRouteData.cs | 0 .../IProxyView.cs | 0 .../IProxyViewContext.cs | 0 ....Mvc.TestDiagnosticListener.Sources.xproj} | 2 +- .../TestDiagnosticListener.cs} | 24 +++++------ .../project.json | 0 .../PartialViewResultTest.cs | 7 ++-- .../PartialViewResultExecutorTest.cs | 38 ++++++++--------- .../ViewFeatures/ViewExecutorTest.cs | 27 ++++++------ .../ViewFeatures/ViewResultExecutorTest.cs | 36 ++++++++-------- .../ViewResultTest.cs | 7 ++-- .../project.json | 4 +- 29 files changed, 158 insertions(+), 217 deletions(-) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources}/IProxyActionContext.cs (100%) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources}/IProxyActionDescriptor.cs (100%) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources}/IProxyActionResult.cs (100%) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources}/IProxyHttpContext.cs (100%) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources}/IProxyRouteData.cs (100%) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources}/IProxyView.cs (100%) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources}/IProxyViewContext.cs (100%) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources.xproj => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources.xproj} (91%) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/TestTelemetryListener.cs => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/TestDiagnosticListener.cs} (90%) rename test/{Microsoft.AspNet.Mvc.TestTelemetryListener.Sources => Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources}/project.json (100%) diff --git a/Mvc.NoFun.sln b/Mvc.NoFun.sln index d13841b640..71040b9d55 100644 --- a/Mvc.NoFun.sln +++ b/Mvc.NoFun.sln @@ -84,7 +84,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Locali EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Localization.Test", "test\Microsoft.AspNet.Mvc.Localization.Test\Microsoft.AspNet.Mvc.Localization.Test.xproj", "{8FC726B5-E766-44E0-8B38-1313B6D8D9A7}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TestTelemetryListener.Sources", "test\Microsoft.AspNet.Mvc.TestTelemetryListener.Sources\Microsoft.AspNet.Mvc.TestTelemetryListener.Sources.xproj", "{9879B5D5-2325-4A81-B4DF-F279FE8FEEB4}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources", "test\Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources\Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources.xproj", "{9879B5D5-2325-4A81-B4DF-F279FE8FEEB4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Mvc.sln b/Mvc.sln index 6d9205325a..41a917fef3 100644 --- a/Mvc.sln +++ b/Mvc.sln @@ -180,7 +180,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Locali EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Localization.Test", "test\Microsoft.AspNet.Mvc.Localization.Test\Microsoft.AspNet.Mvc.Localization.Test.xproj", "{8FC726B5-E766-44E0-8B38-1313B6D8D9A7}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TestTelemetryListener.Sources", "test\Microsoft.AspNet.Mvc.TestTelemetryListener.Sources\Microsoft.AspNet.Mvc.TestTelemetryListener.Sources.xproj", "{9879B5D5-2325-4A81-B4DF-F279FE8FEEB4}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources", "test\Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources\Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources.xproj", "{9879B5D5-2325-4A81-B4DF-F279FE8FEEB4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvoker.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvoker.cs index a07e109f7f..8eac814517 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvoker.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvoker.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Diagnostics.Tracing; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Core; @@ -23,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.Controllers private readonly ControllerActionDescriptor _descriptor; private readonly IControllerFactory _controllerFactory; private readonly IControllerActionArgumentBinder _argumentBinder; -#pragma warning disable 0618 + public ControllerActionInvoker( ActionContext actionContext, IReadOnlyList filterProviders, @@ -37,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.Controllers IReadOnlyList valueProviderFactories, IActionBindingContextAccessor actionBindingContextAccessor, ILogger logger, - TelemetrySource telemetry, + DiagnosticSource diagnosticSource, int maxModelValidationErrors) : base( actionContext, @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.Controllers valueProviderFactories, actionBindingContextAccessor, logger, - telemetry, + diagnosticSource, maxModelValidationErrors) { if (actionContext == null) @@ -112,9 +111,9 @@ namespace Microsoft.AspNet.Mvc.Controllers throw new ArgumentNullException(nameof(logger)); } - if (telemetry == null) + if (diagnosticSource == null) { - throw new ArgumentNullException(nameof(telemetry)); + throw new ArgumentNullException(nameof(diagnosticSource)); } _descriptor = descriptor; @@ -129,7 +128,6 @@ namespace Microsoft.AspNet.Mvc.Controllers "descriptor"); } } -#pragma warning disable 0618 protected override object CreateInstance() { diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvokerProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvokerProvider.cs index 4104725bbb..2218afad0a 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvokerProvider.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/ControllerActionInvokerProvider.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Linq; using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Filters; @@ -18,7 +18,6 @@ namespace Microsoft.AspNet.Mvc.Controllers { public class ControllerActionInvokerProvider : IActionInvokerProvider { -#pragma warning disable 0618 private readonly IControllerActionArgumentBinder _argumentBinder; private readonly IControllerFactory _controllerFactory; private readonly IFilterProvider[] _filterProviders; @@ -30,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.Controllers private readonly IActionBindingContextAccessor _actionBindingContextAccessor; private readonly int _maxModelValidationErrors; private readonly ILogger _logger; - private readonly TelemetrySource _telemetry; + private readonly DiagnosticSource _diagnosticSource; public ControllerActionInvokerProvider( IControllerFactory controllerFactory, @@ -39,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.Controllers IOptions optionsAccessor, IActionBindingContextAccessor actionBindingContextAccessor, ILoggerFactory loggerFactory, - TelemetrySource telemetry) + DiagnosticSource diagnosticSource) { _controllerFactory = controllerFactory; _filterProviders = filterProviders.OrderBy(item => item.Order).ToArray(); @@ -52,9 +51,8 @@ namespace Microsoft.AspNet.Mvc.Controllers _actionBindingContextAccessor = actionBindingContextAccessor; _maxModelValidationErrors = optionsAccessor.Value.MaxModelValidationErrors; _logger = loggerFactory.CreateLogger(); - _telemetry = telemetry; + _diagnosticSource = diagnosticSource; } -#pragma warning restore 0618 public int Order { @@ -86,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.Controllers _valueProviderFactories, _actionBindingContextAccessor, _logger, - _telemetry, + _diagnosticSource, _maxModelValidationErrors); } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Controllers/FilterActionInvoker.cs b/src/Microsoft.AspNet.Mvc.Core/Controllers/FilterActionInvoker.cs index 34c5a346ac..8d94381193 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Controllers/FilterActionInvoker.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Controllers/FilterActionInvoker.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Diagnostics.Tracing; using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Abstractions; @@ -31,9 +30,7 @@ namespace Microsoft.AspNet.Mvc.Controllers private readonly IReadOnlyList _valueProviderFactories; private readonly IActionBindingContextAccessor _actionBindingContextAccessor; private readonly ILogger _logger; -#pragma warning disable 0618 - private readonly TelemetrySource _telemetry; -#pragma warning restore 0618 + private readonly DiagnosticSource _diagnosticSource; private readonly int _maxModelValidationErrors; private IFilterMetadata[] _filters; @@ -62,8 +59,7 @@ namespace Microsoft.AspNet.Mvc.Controllers "Request was short circuited at exception filter '{ExceptionFilter}'."; private const string ResultFilterShortCircuitLogMessage = "Request was short circuited at result filter '{ResultFilter}'."; - -#pragma warning disable 0618 + public FilterActionInvoker( ActionContext actionContext, IReadOnlyList filterProviders, @@ -74,7 +70,7 @@ namespace Microsoft.AspNet.Mvc.Controllers IReadOnlyList valueProviderFactories, IActionBindingContextAccessor actionBindingContextAccessor, ILogger logger, - TelemetrySource telemetry, + DiagnosticSource diagnosticSource, int maxModelValidationErrors) { if (actionContext == null) @@ -122,9 +118,9 @@ namespace Microsoft.AspNet.Mvc.Controllers throw new ArgumentNullException(nameof(logger)); } - if (telemetry == null) + if (diagnosticSource == null) { - throw new ArgumentNullException(nameof(telemetry)); + throw new ArgumentNullException(nameof(diagnosticSource)); } ActionContext = actionContext; @@ -137,10 +133,9 @@ namespace Microsoft.AspNet.Mvc.Controllers _valueProviderFactories = valueProviderFactories; _actionBindingContextAccessor = actionBindingContextAccessor; _logger = logger; - _telemetry = telemetry; + _diagnosticSource = diagnosticSource; _maxModelValidationErrors = maxModelValidationErrors; } -#pragma warning restore 0618 protected ActionContext ActionContext { get; private set; } @@ -656,10 +651,9 @@ namespace Microsoft.AspNet.Mvc.Controllers try { -#pragma warning disable 0618 - if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionMethod")) + if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionMethod")) { - _telemetry.WriteTelemetry( + _diagnosticSource.Write( "Microsoft.AspNet.Mvc.BeforeActionMethod", new { @@ -668,16 +662,14 @@ namespace Microsoft.AspNet.Mvc.Controllers controller = _actionExecutingContext.Controller }); } -#pragma warning restore 0618 result = await InvokeActionAsync(_actionExecutingContext); } finally { -#pragma warning disable 0618 - if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterActionMethod")) + if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterActionMethod")) { - _telemetry.WriteTelemetry( + _diagnosticSource.Write( "Microsoft.AspNet.Mvc.AfterActionMethod", new { @@ -687,7 +679,6 @@ namespace Microsoft.AspNet.Mvc.Controllers result = result }); } -#pragma warning restore 0618 } _actionExecutedContext = new ActionExecutedContext( @@ -835,14 +826,12 @@ namespace Microsoft.AspNet.Mvc.Controllers private async Task InvokeResultAsync(IActionResult result) { -#pragma warning disable 0618 - if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionResult")) + if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.BeforeActionResult")) { - _telemetry.WriteTelemetry( + _diagnosticSource.Write( "Microsoft.AspNet.Mvc.BeforeActionResult", new { actionContext = ActionContext, result = result }); } -#pragma warning restore 0618 try { @@ -850,14 +839,12 @@ namespace Microsoft.AspNet.Mvc.Controllers } finally { -#pragma warning disable 0618 - if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterActionResult")) + if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterActionResult")) { - _telemetry.WriteTelemetry( + _diagnosticSource.Write( "Microsoft.AspNet.Mvc.AfterActionResult", new { actionContext = ActionContext, result = result }); } -#pragma warning restore 0618 } } diff --git a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/MvcRouteHandler.cs b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/MvcRouteHandler.cs index 95da719e7c..ef4dd0dd8e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Infrastructure/MvcRouteHandler.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Infrastructure/MvcRouteHandler.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Abstractions; @@ -21,9 +21,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure private IActionInvokerFactory _actionInvokerFactory; private IActionSelector _actionSelector; private ILogger _logger; -#pragma warning disable 0618 - private TelemetrySource _telemetry; -#pragma warning restore 0618 + private DiagnosticSource _diagnosticSource; public VirtualPathData GetVirtualPath(VirtualPathContext context) { @@ -86,14 +84,12 @@ namespace Microsoft.AspNet.Mvc.Infrastructure { context.RouteData = newRouteData; -#pragma warning disable 0618 - if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeAction")) + if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.BeforeAction")) { - _telemetry.WriteTelemetry( + _diagnosticSource.Write( "Microsoft.AspNet.Mvc.BeforeAction", new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData }); } -#pragma warning restore 0618 using (_logger.BeginScope("ActionId: {ActionId}", actionDescriptor.Id)) { @@ -105,14 +101,12 @@ namespace Microsoft.AspNet.Mvc.Infrastructure } finally { -#pragma warning disable 0618 - if (_telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterAction")) + if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterAction")) { - _telemetry.WriteTelemetry( + _diagnosticSource.Write( "Microsoft.AspNet.Mvc.AfterAction", new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData }); } -#pragma warning restore 0618 if (!context.IsHandled) { @@ -159,13 +153,11 @@ namespace Microsoft.AspNet.Mvc.Infrastructure var factory = context.RequestServices.GetRequiredService(); _logger = factory.CreateLogger(); } - -#pragma warning disable 0618 - if (_telemetry == null) + + if (_diagnosticSource == null) { - _telemetry = context.RequestServices.GetRequiredService(); + _diagnosticSource = context.RequestServices.GetRequiredService(); } -#pragma warning restore 0618 } } } diff --git a/src/Microsoft.AspNet.Mvc.Core/project.json b/src/Microsoft.AspNet.Mvc.Core/project.json index eaf5177fdc..9da116951b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/project.json +++ b/src/Microsoft.AspNet.Mvc.Core/project.json @@ -32,7 +32,7 @@ "version": "1.0.0-*", "type": "build" }, - "System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*" + "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" }, "frameworks": { "dnx451": { diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs index 9298d4523a..0ecb853c85 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.ViewEngines; @@ -16,22 +16,21 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public class PartialViewResultExecutor : ViewExecutor { -#pragma warning disable 0618 /// /// Creates a new . /// /// The . /// The . /// The . - /// The . + /// The . /// The . public PartialViewResultExecutor( IOptions viewOptions, IHttpResponseStreamWriterFactory writerFactory, ICompositeViewEngine viewEngine, - TelemetrySource telemetry, + DiagnosticSource diagnosticSource, ILoggerFactory loggerFactory) - : base(viewOptions, writerFactory, viewEngine, telemetry) + : base(viewOptions, writerFactory, viewEngine, diagnosticSource) { if (loggerFactory == null) { @@ -40,7 +39,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Logger = loggerFactory.CreateLogger(); } -#pragma warning restore 0618 /// /// Gets the . @@ -71,10 +69,9 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var result = viewEngine.FindPartialView(actionContext, viewName); if (result.Success) { -#pragma warning disable 0618 - if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.ViewFound")) + if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.ViewFound")) { - Telemetry.WriteTelemetry( + DiagnosticSource.Write( "Microsoft.AspNet.Mvc.ViewFound", new { @@ -85,15 +82,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures view = result.View, }); } -#pragma warning restore 0618 + Logger.LogVerbose("The partial view '{PartialViewName}' was found.", viewName); } else { -#pragma warning disable 0618 - if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.ViewNotFound")) + if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.ViewNotFound")) { - Telemetry.WriteTelemetry( + DiagnosticSource.Write( "Microsoft.AspNet.Mvc.ViewNotFound", new { @@ -104,7 +100,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures searchedLocations = result.SearchedLocations }); } -#pragma warning restore 0618 Logger.LogError( "The partial view '{PartialViewName}' was not found. Searched locations: {SearchedViewLocations}", diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewExecutor.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewExecutor.cs index 1da471999e..dee4e8ec37 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewExecutor.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewExecutor.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Infrastructure; @@ -26,19 +26,18 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Encoding = Encoding.UTF8 }.CopyAsReadOnly(); -#pragma warning disable 0618 /// /// Creates a new . /// /// The . /// The . /// The . - /// The . + /// The . public ViewExecutor( IOptions viewOptions, IHttpResponseStreamWriterFactory writerFactory, ICompositeViewEngine viewEngine, - TelemetrySource telemetry) + DiagnosticSource diagnosticSource) { if (viewOptions == null) { @@ -55,22 +54,21 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures throw new ArgumentNullException(nameof(viewEngine)); } - if (telemetry == null) + if (diagnosticSource == null) { - throw new ArgumentNullException(nameof(telemetry)); + throw new ArgumentNullException(nameof(diagnosticSource)); } ViewOptions = viewOptions.Value; WriterFactory = writerFactory; ViewEngine = viewEngine; - Telemetry = telemetry; + DiagnosticSource = diagnosticSource; } /// - /// Gets the . + /// Gets the . /// - protected TelemetrySource Telemetry { get; } -#pragma warning restore 0618 + protected DiagnosticSource DiagnosticSource { get; } /// /// Gets the default . @@ -159,26 +157,22 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures tempData, writer, ViewOptions.HtmlHelperOptions); - -#pragma warning disable 0618 - if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.BeforeView")) + + if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.BeforeView")) { - Telemetry.WriteTelemetry( + DiagnosticSource.Write( "Microsoft.AspNet.Mvc.BeforeView", new { view = view, viewContext = viewContext, }); } -#pragma warning restore 0618 await view.RenderAsync(viewContext); - -#pragma warning disable 0618 - if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.AfterView")) + + if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.AfterView")) { - Telemetry.WriteTelemetry( + DiagnosticSource.Write( "Microsoft.AspNet.Mvc.AfterView", new { view = view, viewContext = viewContext, }); } -#pragma warning restore 0618 // Perf: Invoke FlushAsync to ensure any buffered content is asynchronously written to the underlying // response asynchronously. In the absence of this line, the buffer gets synchronously written to the diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs index b64edcb02f..74f96731b3 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.ViewEngines; @@ -16,22 +16,21 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures /// public class ViewResultExecutor : ViewExecutor { -#pragma warning disable 0618 /// /// Creates a new . /// /// The . /// The . /// The . - /// The . + /// The . /// The . public ViewResultExecutor( IOptions viewOptions, IHttpResponseStreamWriterFactory writerFactory, ICompositeViewEngine viewEngine, - TelemetrySource telemetry, + DiagnosticSource diagnosticSource, ILoggerFactory loggerFactory) - : base(viewOptions, writerFactory, viewEngine, telemetry) + : base(viewOptions, writerFactory, viewEngine, diagnosticSource) { if (loggerFactory == null) { @@ -40,7 +39,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Logger = loggerFactory.CreateLogger(); } -#pragma warning restore 0618 /// /// Gets the . @@ -71,10 +69,9 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var result = viewEngine.FindView(actionContext, viewName); if (result.Success) { -#pragma warning disable 0618 - if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.ViewFound")) + if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.ViewFound")) { - Telemetry.WriteTelemetry( + DiagnosticSource.Write( "Microsoft.AspNet.Mvc.ViewFound", new { @@ -85,16 +82,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures view = result.View, }); } -#pragma warning restore 0618 Logger.LogVerbose("The view '{ViewName}' was found.", viewName); } else { -#pragma warning disable 0618 - if (Telemetry.IsEnabled("Microsoft.AspNet.Mvc.ViewNotFound")) + if (DiagnosticSource.IsEnabled("Microsoft.AspNet.Mvc.ViewNotFound")) { - Telemetry.WriteTelemetry( + DiagnosticSource.Write( "Microsoft.AspNet.Mvc.ViewNotFound", new { @@ -105,7 +100,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures searchedLocations = result.SearchedLocations }); } -#pragma warning restore 0618 Logger.LogError( "The view '{ViewName}' was not found. Searched locations: {SearchedViewLocations}", diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionInvokerTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionInvokerTest.cs index 8c2bc64d37..302bb1a239 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionInvokerTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Controllers/ControllerActionInvokerTest.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -2041,7 +2041,7 @@ namespace Microsoft.AspNet.Mvc.Controllers filterProvider .SetupGet(fp => fp.Order) .Returns(-1000); -#pragma warning disable 0618 + var invoker = new TestControllerActionInvoker( actionContext, new[] { filterProvider.Object }, @@ -2055,9 +2055,8 @@ namespace Microsoft.AspNet.Mvc.Controllers new IValueProviderFactory[0], new ActionBindingContextAccessor(), new NullLoggerFactory().CreateLogger(), - new TelemetryListener("Microsoft.AspNet"), + new DiagnosticListener("Microsoft.AspNet"), maxAllowedErrorsInModelState); -#pragma warning restore 0618 return invoker; } @@ -2101,7 +2100,7 @@ namespace Microsoft.AspNet.Mvc.Controllers .Returns(new TestController()); var metadataProvider = new EmptyModelMetadataProvider(); -#pragma warning disable 0618 + var invoker = new ControllerActionInvoker( actionContext, new List(), @@ -2117,9 +2116,8 @@ namespace Microsoft.AspNet.Mvc.Controllers new IValueProviderFactory[0], new ActionBindingContextAccessor(), new NullLoggerFactory().CreateLogger(), - new TelemetryListener("Microsoft.AspNet"), + new DiagnosticListener("Microsoft.AspNet"), 200); -#pragma warning restore 0618 // Act await invoker.InvokeAsync(); @@ -2206,7 +2204,6 @@ namespace Microsoft.AspNet.Mvc.Controllers private class TestControllerActionInvoker : ControllerActionInvoker { -#pragma warning disable 0618 public TestControllerActionInvoker( ActionContext actionContext, IFilterProvider[] filterProvider, @@ -2220,7 +2217,7 @@ namespace Microsoft.AspNet.Mvc.Controllers IReadOnlyList valueProviderFactories, IActionBindingContextAccessor actionBindingContext, ILogger logger, - TelemetrySource telemetry, + DiagnosticSource diagnosticSource, int maxAllowedErrorsInModelState) : base( actionContext, @@ -2235,12 +2232,11 @@ namespace Microsoft.AspNet.Mvc.Controllers valueProviderFactories, actionBindingContext, logger, - telemetry, + diagnosticSource, maxAllowedErrorsInModelState) { ControllerFactory = controllerFactory; } -#pragma warning restore 0618 public MockControllerFactory ControllerFactory { get; } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/MvcRouteHandlerTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/MvcRouteHandlerTests.cs index 1c9e79c881..47d04a3ecd 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/MvcRouteHandlerTests.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/Infrastructure/MvcRouteHandlerTests.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc.Abstractions; @@ -193,12 +193,12 @@ namespace Microsoft.AspNet.Mvc.Infrastructure } [Fact] - public async Task RouteAsync_Notifies_ActionSelected() + public async Task RouteAsync_WritesDiagnostic_ActionSelected() { // Arrange - var listener = new TestTelemetryListener(); + var listener = new TestDiagnosticListener(); - var context = CreateRouteContext(telemetryListener: listener); + var context = CreateRouteContext(diagnosticListener: listener); context.RouteData.Values.Add("tag", "value"); var handler = new MvcRouteHandler(); @@ -218,12 +218,12 @@ namespace Microsoft.AspNet.Mvc.Infrastructure } [Fact] - public async Task RouteAsync_Notifies_ActionInvoked() + public async Task RouteAsync_WritesDiagnostic_ActionInvoked() { // Arrange - var listener = new TestTelemetryListener(); + var listener = new TestDiagnosticListener(); - var context = CreateRouteContext(telemetryListener: listener); + var context = CreateRouteContext(diagnosticListener: listener); var handler = new MvcRouteHandler(); @@ -241,7 +241,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, IOptions optionsAccessor = null, - object telemetryListener = null) + object diagnosticListener = null) { if (actionDescriptor == null) { @@ -280,13 +280,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure { optionsAccessor = new TestOptionsManager(); } -#pragma warning disable 0618 - var telemetry = new TelemetryListener("Microsoft.AspNet"); - if (telemetryListener != null) + + var diagnosticSource = new DiagnosticListener("Microsoft.AspNet"); + if (diagnosticListener != null) { - telemetry.SubscribeWithAdapter(telemetryListener); + diagnosticSource.SubscribeWithAdapter(diagnosticListener); } -#pragma warning restore 0618 + var httpContext = new Mock(); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionContextAccessor))) .Returns(new ActionContextAccessor()); @@ -300,10 +300,8 @@ namespace Microsoft.AspNet.Mvc.Infrastructure .Returns(new MvcMarkerService()); httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions))) .Returns(optionsAccessor); -#pragma warning disable 0618 - httpContext.Setup(h => h.RequestServices.GetService(typeof(TelemetrySource))) - .Returns(telemetry); -#pragma warning restore 0618 + httpContext.Setup(h => h.RequestServices.GetService(typeof(DiagnosticSource))) + .Returns(diagnosticSource); return new RouteContext(httpContext.Object); } } diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/project.json b/test/Microsoft.AspNet.Mvc.Core.Test/project.json index b2b96733e3..ec1712980c 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/project.json +++ b/test/Microsoft.AspNet.Mvc.Core.Test/project.json @@ -10,14 +10,14 @@ "type": "build" }, "Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*", - "Microsoft.AspNet.Mvc.TestTelemetryListener.Sources": { + "Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources": { "version": "6.0.0-*", "type": "build" }, "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Extensions.DependencyInjection": "1.0.0-*", "Microsoft.Extensions.Logging.Testing": "1.0.0-*", - "Microsoft.Extensions.TelemetryAdapter": "1.0.0-*", + "Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*", "Microsoft.Extensions.WebEncoders.Testing": "1.0.0-*", "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyActionContext.cs b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyActionContext.cs similarity index 100% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyActionContext.cs rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyActionContext.cs diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyActionDescriptor.cs b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyActionDescriptor.cs similarity index 100% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyActionDescriptor.cs rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyActionDescriptor.cs diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyActionResult.cs b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyActionResult.cs similarity index 100% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyActionResult.cs rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyActionResult.cs diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyHttpContext.cs b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyHttpContext.cs similarity index 100% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyHttpContext.cs rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyHttpContext.cs diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyRouteData.cs b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyRouteData.cs similarity index 100% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyRouteData.cs rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyRouteData.cs diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyView.cs b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyView.cs similarity index 100% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyView.cs rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyView.cs diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyViewContext.cs b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyViewContext.cs similarity index 100% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/IProxyViewContext.cs rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/IProxyViewContext.cs diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources.xproj b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources.xproj similarity index 91% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources.xproj rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources.xproj index 61e335c36f..7828173ba1 100644 --- a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources.xproj +++ b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources.xproj @@ -7,7 +7,7 @@ 9879b5d5-2325-4a81-b4df-f279fe8feeb4 - Microsoft.AspNet.Mvc.TestTelemetryListener.Sources + Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/TestTelemetryListener.cs b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/TestDiagnosticListener.cs similarity index 90% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/TestTelemetryListener.cs rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/TestDiagnosticListener.cs index 32d6af767e..57c570ac50 100644 --- a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/TestTelemetryListener.cs +++ b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/TestDiagnosticListener.cs @@ -2,11 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using Microsoft.Extensions.TelemetryAdapter; +using Microsoft.Extensions.DiagnosticAdapter; namespace Microsoft.AspNet.Mvc { - public class TestTelemetryListener + public class TestDiagnosticListener { public class OnBeforeActionEventData { @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc public OnBeforeActionEventData BeforeAction { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.BeforeAction")] + [DiagnosticName("Microsoft.AspNet.Mvc.BeforeAction")] public virtual void OnBeforeAction( IProxyHttpContext httpContext, IProxyRouteData routeData, @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Mvc public OnAfterActionEventData AfterAction { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.AfterAction")] + [DiagnosticName("Microsoft.AspNet.Mvc.AfterAction")] public virtual void OnAfterAction( IProxyHttpContext httpContext, IProxyActionDescriptor actionDescriptor) @@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Mvc public OnBeforeActionMethodEventData BeforeActionMethod { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.BeforeActionMethod")] + [DiagnosticName("Microsoft.AspNet.Mvc.BeforeActionMethod")] public virtual void OnBeforeActionMethod( IProxyActionContext actionContext, IReadOnlyDictionary arguments) @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Mvc public OnAfterActionMethodEventData AfterActionMethod { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.AfterActionMethod")] + [DiagnosticName("Microsoft.AspNet.Mvc.AfterActionMethod")] public virtual void OnAfterActionMethod( IProxyActionContext actionContext, IProxyActionResult result) @@ -99,7 +99,7 @@ namespace Microsoft.AspNet.Mvc public OnBeforeActionResultEventData BeforeActionResult { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.BeforeActionResult")] + [DiagnosticName("Microsoft.AspNet.Mvc.BeforeActionResult")] public virtual void OnBeforeActionResult(IProxyActionContext actionContext, IProxyActionResult result) { BeforeActionResult = new OnBeforeActionResultEventData() @@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Mvc public OnAfterActionResultEventData AfterActionResult { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.AfterActionResult")] + [DiagnosticName("Microsoft.AspNet.Mvc.AfterActionResult")] public virtual void OnAfterActionResult(IProxyActionContext actionContext, IProxyActionResult result) { AfterActionResult = new OnAfterActionResultEventData() @@ -138,7 +138,7 @@ namespace Microsoft.AspNet.Mvc public OnViewFoundEventData ViewFound { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.ViewFound")] + [DiagnosticName("Microsoft.AspNet.Mvc.ViewFound")] public virtual void OnViewFound( IProxyActionContext actionContext, bool isPartial, @@ -167,7 +167,7 @@ namespace Microsoft.AspNet.Mvc public OnViewNotFoundEventData ViewNotFound { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.ViewNotFound")] + [DiagnosticName("Microsoft.AspNet.Mvc.ViewNotFound")] public virtual void OnViewNotFound( IProxyActionContext actionContext, bool isPartial, @@ -193,7 +193,7 @@ namespace Microsoft.AspNet.Mvc public OnBeforeViewEventData BeforeView { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.BeforeView")] + [DiagnosticName("Microsoft.AspNet.Mvc.BeforeView")] public virtual void OnBeforeView(IProxyView view, IProxyViewContext viewContext) { BeforeView = new OnBeforeViewEventData() @@ -211,7 +211,7 @@ namespace Microsoft.AspNet.Mvc public OnAfterViewEventData AfterView { get; set; } - [TelemetryName("Microsoft.AspNet.Mvc.AfterView")] + [DiagnosticName("Microsoft.AspNet.Mvc.AfterView")] public virtual void OnAfterView(IProxyView view, IProxyViewContext viewContext) { AfterView = new OnAfterViewEventData() diff --git a/test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/project.json b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/project.json similarity index 100% rename from test/Microsoft.AspNet.Mvc.TestTelemetryListener.Sources/project.json rename to test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/project.json diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/PartialViewResultTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/PartialViewResultTest.cs index ff614e3464..34a60f62cf 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/PartialViewResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/PartialViewResultTest.cs @@ -3,7 +3,7 @@ #if MOCK_SUPPORT using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; @@ -105,14 +105,13 @@ namespace Microsoft.AspNet.Mvc private HttpContext GetHttpContext() { var options = new TestOptionsManager(); -#pragma warning disable 0618 + var viewExecutor = new PartialViewResultExecutor( options, new TestHttpResponseStreamWriterFactory(), new CompositeViewEngine(options), - new TelemetryListener("Microsoft.AspNet"), + new DiagnosticListener("Microsoft.AspNet"), NullLoggerFactory.Instance); -#pragma warning restore 0618 var services = new ServiceCollection(); services.AddInstance(viewExecutor); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs index f19ae1e77f..694c0466c5 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #if MOCK_SUPPORT -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Mvc.Abstractions; @@ -70,18 +70,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures // Assert Assert.Equal(viewName, viewEngineResult.ViewName); } - -#pragma warning disable 0618 + [Fact] - public void FindView_Notifies_ViewFound() + public void FindView_WritesDiagnostic_ViewFound() { // Arrange - var telemetry = new TelemetryListener("Test"); - var listener = new TestTelemetryListener(); - telemetry.SubscribeWithAdapter(listener); + var diagnosticSource = new DiagnosticListener("Test"); + var listener = new TestDiagnosticListener(); + diagnosticSource.SubscribeWithAdapter(listener); var context = GetActionContext(); - var executor = GetViewExecutor(telemetry); + var executor = GetViewExecutor(diagnosticSource); var viewName = "myview"; var viewResult = new PartialViewResult @@ -106,15 +105,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures } [Fact] - public void FindView_Notifies_ViewNotFound() + public void FindView_WritesDiagnostic_ViewNotFound() { // Arrange - var telemetry = new TelemetryListener("Test"); - var listener = new TestTelemetryListener(); - telemetry.SubscribeWithAdapter(listener); + var diagnosticSource = new DiagnosticListener("Test"); + var listener = new TestDiagnosticListener(); + diagnosticSource.SubscribeWithAdapter(listener); var context = GetActionContext(); - var executor = GetViewExecutor(telemetry); + var executor = GetViewExecutor(diagnosticSource); var viewName = "myview"; var viewEngine = new Mock(MockBehavior.Strict); @@ -142,7 +141,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Assert.Equal(new string[] { "location/myview" }, listener.ViewNotFound.SearchedLocations); Assert.Equal("myview", listener.ViewNotFound.ViewName); } -#pragma warning restore 0618 [Fact] public async Task ExecuteAsync_UsesContentType_FromPartialViewResult() @@ -201,13 +199,12 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures { return new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()); } - -#pragma warning disable 0618 - private PartialViewResultExecutor GetViewExecutor(TelemetrySource telemetry = null) + + private PartialViewResultExecutor GetViewExecutor(DiagnosticSource diagnosticSource = null) { - if (telemetry == null) + if (diagnosticSource == null) { - telemetry = new TelemetryListener("Test"); + diagnosticSource = new DiagnosticListener("Test"); } var viewEngine = new Mock(MockBehavior.Strict); @@ -222,12 +219,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures options, new TestHttpResponseStreamWriterFactory(), new CompositeViewEngine(options), - telemetry, + diagnosticSource, NullLoggerFactory.Instance); return viewExecutor; } -#pragma warning restore 0618 } } #endif diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewExecutorTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewExecutorTest.cs index 0f4efa6fe8..9290b4e090 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewExecutorTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewExecutorTest.cs @@ -3,7 +3,7 @@ #if MOCK_SUPPORT using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.IO; using System.Text; using System.Threading; @@ -146,9 +146,9 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Assert.Equal(500, context.Response.StatusCode); Assert.Equal("abcd", Encoding.UTF8.GetString(memoryStream.ToArray())); } -#pragma warning disable 0618 + [Fact] - public async Task ExecuteAsync_WritesTelemetry() + public async Task ExecuteAsync_WritesDiagnostic() { // Arrange var view = CreateView(async (v) => @@ -166,12 +166,12 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures new ActionDescriptor()); var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); - var adapter = new TestTelemetryListener(); + var adapter = new TestDiagnosticListener(); - var telemetryListener = new TelemetryListener("Test"); - telemetryListener.SubscribeWithAdapter(adapter); + var diagnosticSource = new DiagnosticListener("Test"); + diagnosticSource.SubscribeWithAdapter(adapter); - var viewExecutor = CreateViewExecutor(telemetryListener); + var viewExecutor = CreateViewExecutor(diagnosticSource); // Act await viewExecutor.ExecuteAsync( @@ -190,7 +190,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Assert.NotNull(adapter.AfterView?.View); Assert.NotNull(adapter.AfterView?.ViewContext); } -#pragma warning restore 0618 + [Fact] public async Task ExecuteAsync_DoesNotWriteToResponse_OnceExceptionIsThrown() { @@ -277,21 +277,20 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures return view.Object; } -#pragma warning disable 0618 - private ViewExecutor CreateViewExecutor(TelemetryListener listener = null) + + private ViewExecutor CreateViewExecutor(DiagnosticListener diagnosticSource = null) { - if (listener == null) + if (diagnosticSource == null) { - listener = new TelemetryListener("Test"); + diagnosticSource = new DiagnosticListener("Test"); } return new ViewExecutor( new TestOptionsManager(), new TestHttpResponseStreamWriterFactory(), new Mock(MockBehavior.Strict).Object, - listener); + diagnosticSource); } -#pragma warning restore 0618 } } #endif \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs index 7628156025..942b88b0c8 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #if MOCK_SUPPORT -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Http.Internal; using Microsoft.AspNet.Mvc.Abstractions; @@ -71,17 +71,16 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Assert.Equal(viewName, viewEngineResult.ViewName); } -#pragma warning disable 0618 [Fact] - public void FindView_Notifies_ViewFound() + public void FindView_WritesDiagnostic_ViewFound() { // Arrange - var telemetry = new TelemetryListener("Test"); - var listener = new TestTelemetryListener(); - telemetry.SubscribeWithAdapter(listener); + var diagnosticSource = new DiagnosticListener("Test"); + var listener = new TestDiagnosticListener(); + diagnosticSource.SubscribeWithAdapter(listener); var context = GetActionContext(); - var executor = GetViewExecutor(telemetry); + var executor = GetViewExecutor(diagnosticSource); var viewName = "myview"; var viewResult = new ViewResult @@ -106,15 +105,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures } [Fact] - public void FindView_Notifies_ViewNotFound() + public void FindView_WritesDiagnostic_ViewNotFound() { // Arrange - var telemetry = new TelemetryListener("Test"); - var listener = new TestTelemetryListener(); - telemetry.SubscribeWithAdapter(listener); + var diagnosticSource = new DiagnosticListener("Test"); + var listener = new TestDiagnosticListener(); + diagnosticSource.SubscribeWithAdapter(listener); var context = GetActionContext(); - var executor = GetViewExecutor(telemetry); + var executor = GetViewExecutor(diagnosticSource); var viewName = "myview"; var viewEngine = new Mock(); @@ -142,7 +141,6 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Assert.Equal(new string[] { "location/myview" }, listener.ViewNotFound.SearchedLocations); Assert.Equal("myview", listener.ViewNotFound.ViewName); } -#pragma warning restore 0618 [Fact] public async Task ExecuteAsync_UsesContentType_FromViewResult() @@ -201,13 +199,12 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures { return new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()); } - -#pragma warning disable 0618 - private ViewResultExecutor GetViewExecutor(TelemetrySource telemetry = null) + + private ViewResultExecutor GetViewExecutor(DiagnosticListener diagnosticSource = null) { - if (telemetry == null) + if (diagnosticSource == null) { - telemetry = new TelemetryListener("Test"); + diagnosticSource = new DiagnosticListener("Test"); } var viewEngine = new Mock(MockBehavior.Strict); @@ -222,12 +219,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures options, new TestHttpResponseStreamWriterFactory(), new CompositeViewEngine(options), - telemetry, + diagnosticSource, NullLoggerFactory.Instance); return viewExecutor; } -#pragma warning restore 0618 } } #endif diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs index 3fca82ee03..9631e4b639 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs @@ -3,7 +3,7 @@ #if MOCK_SUPPORT using System; -using System.Diagnostics.Tracing; +using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Internal; @@ -105,14 +105,13 @@ namespace Microsoft.AspNet.Mvc private HttpContext GetHttpContext() { var options = new TestOptionsManager(); -#pragma warning disable 0618 + var viewExecutor = new ViewResultExecutor( options, new TestHttpResponseStreamWriterFactory(), new CompositeViewEngine(options), - new TelemetryListener("Microsoft.AspNet"), + new DiagnosticListener("Microsoft.AspNet"), NullLoggerFactory.Instance); -#pragma warning restore 0618 var services = new ServiceCollection(); services.AddInstance(viewExecutor); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/project.json b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/project.json index c446932dbd..cd3841d71f 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/project.json +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/project.json @@ -10,14 +10,14 @@ "version": "6.0.0-*", "type": "build" }, - "Microsoft.AspNet.Mvc.TestTelemetryListener.Sources": { + "Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources": { "version": "6.0.0-*", "type": "build" }, "Microsoft.AspNet.Testing": "1.0.0-*", "Microsoft.Extensions.DependencyInjection": "1.0.0-*", "Microsoft.Extensions.Logging.Testing": "1.0.0-*", - "Microsoft.Extensions.TelemetryAdapter": "1.0.0-*", + "Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*", "Microsoft.Extensions.WebEncoders.Testing": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" },