diff --git a/EventNotification.sln b/EventNotification.sln index 9641271..b299c69 100644 --- a/EventNotification.sln +++ b/EventNotification.sln @@ -1,4 +1,3 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.23107.0 @@ -7,9 +6,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8B66E199-1AF EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D75011A4-DEEE-48DE-BB83-CE042F2AC05B}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.TelemetryAdapter", "src\Microsoft.Extensions.TelemetryAdapter\Microsoft.Extensions.TelemetryAdapter.xproj", "{87808F3C-362E-4261-AA4A-EE40BA39D64E}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.DiagnosticAdapter", "src\Microsoft.Extensions.DiagnosticAdapter\Microsoft.Extensions.DiagnosticAdapter.xproj", "{87808F3C-362E-4261-AA4A-EE40BA39D64E}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.TelemetryAdapter.Test", "test\Microsoft.Extensions.TelemetryAdapter.Test\Microsoft.Extensions.TelemetryAdapter.Test.xproj", "{FB993EEE-FF13-4454-BF49-F60DD0A531F7}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.DiagnosticAdapter.Test", "test\Microsoft.Extensions.DiagnosticAdapter.Test\Microsoft.Extensions.DiagnosticAdapter.Test.xproj", "{02754747-C385-4662-AD58-49CE54C3D7AF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,16 +20,16 @@ Global {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Debug|Any CPU.Build.0 = Debug|Any CPU {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Release|Any CPU.ActiveCfg = Release|Any CPU {87808F3C-362E-4261-AA4A-EE40BA39D64E}.Release|Any CPU.Build.0 = Release|Any CPU - {FB993EEE-FF13-4454-BF49-F60DD0A531F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FB993EEE-FF13-4454-BF49-F60DD0A531F7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FB993EEE-FF13-4454-BF49-F60DD0A531F7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FB993EEE-FF13-4454-BF49-F60DD0A531F7}.Release|Any CPU.Build.0 = Release|Any CPU + {02754747-C385-4662-AD58-49CE54C3D7AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {02754747-C385-4662-AD58-49CE54C3D7AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {02754747-C385-4662-AD58-49CE54C3D7AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {02754747-C385-4662-AD58-49CE54C3D7AF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {87808F3C-362E-4261-AA4A-EE40BA39D64E} = {8B66E199-1AFE-4B68-AC71-4521C46EC4CD} - {FB993EEE-FF13-4454-BF49-F60DD0A531F7} = {D75011A4-DEEE-48DE-BB83-CE042F2AC05B} + {02754747-C385-4662-AD58-49CE54C3D7AF} = {D75011A4-DEEE-48DE-BB83-CE042F2AC05B} EndGlobalSection EndGlobal diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json index 40fbfb1..e205bff 100644 --- a/NuGetPackageVerifier.json +++ b/NuGetPackageVerifier.json @@ -9,7 +9,7 @@ "StrictSemanticVersionValidationRule" ], "packages": { - "Microsoft.Extensions.TelemetryAdapter": { } + "Microsoft.Extensions.DiagnosticAdapter": { } } }, "Default": { // Rules to run for packages not listed in any other set. @@ -22,4 +22,4 @@ "StrictSemanticVersionValidationRule" ] } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 9dc1cb8..b3614e2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ EventNotification Notice ------- -The infrastructure for publishing notifications has moved to the .Net framework. See the new `TelemetrySource` and `TelemetryListerner` APIs in the `System.Diagnostics.Tracing.Telemetry` package. The infrastructure provided here is for subscribing to events using runtime-generated proxies. +The infrastructure for publishing notifications has moved to the .Net framework. See the new `DiagnosticSource` and `DiagnosticListerner` APIs in the `System.Diagnostics.DiagnosticSource` package. The infrastructure provided here is for subscribing to events using runtime-generated proxies. AppVeyor: [![AppVeyor](https://ci.appveyor.com/api/projects/status/t1bk7hrnqqvlx0fa/branch/dev?svg=true)](https://ci.appveyor.com/project/aspnetci/EventNotification/branch/dev) diff --git a/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticListenerExtensions.cs b/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticListenerExtensions.cs new file mode 100644 index 0000000..5882b40 --- /dev/null +++ b/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticListenerExtensions.cs @@ -0,0 +1,25 @@ +// 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 Microsoft.Extensions.DiagnosticAdapter; + +namespace System.Diagnostics +{ + public static class DiagnosticListenerExtensions + { + public static IDisposable SubscribeWithAdapter(this DiagnosticListener diagnostic, object target) + { + var adapter = new DiagnosticSourceAdapter(target); + return diagnostic.Subscribe(adapter, adapter.IsEnabled); + } + + public static IDisposable SubscribeWithAdapter( + this DiagnosticListener diagnostic, + object target, + Func isEnabled) + { + var adapter = new DiagnosticSourceAdapter(target, isEnabled); + return diagnostic.Subscribe(adapter, adapter.IsEnabled); + } + } +} diff --git a/src/Microsoft.Extensions.TelemetryAdapter/TelemetryNameAttribute.cs b/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticNameAttribute.cs similarity index 64% rename from src/Microsoft.Extensions.TelemetryAdapter/TelemetryNameAttribute.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticNameAttribute.cs index 12838ff..8d8a6be 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/TelemetryNameAttribute.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticNameAttribute.cs @@ -3,11 +3,11 @@ using System; -namespace Microsoft.Extensions.TelemetryAdapter +namespace Microsoft.Extensions.DiagnosticAdapter { - public class TelemetryNameAttribute : Attribute + public class DiagnosticNameAttribute : Attribute { - public TelemetryNameAttribute(string name) + public DiagnosticNameAttribute(string name) { Name = name; } diff --git a/src/Microsoft.Extensions.TelemetryAdapter/TelemetrySourceAdapter.cs b/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticSourceAdapter.cs similarity index 73% rename from src/Microsoft.Extensions.TelemetryAdapter/TelemetrySourceAdapter.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticSourceAdapter.cs index 5eb9ba5..cdada33 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/TelemetrySourceAdapter.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/DiagnosticSourceAdapter.cs @@ -7,27 +7,27 @@ using System.Collections.Generic; using System.Diagnostics; using System.Reflection; -namespace Microsoft.Extensions.TelemetryAdapter +namespace Microsoft.Extensions.DiagnosticAdapter { - public class TelemetrySourceAdapter : IObserver> + public class DiagnosticSourceAdapter : IObserver> { private readonly Listener _listener; - private readonly ITelemetrySourceMethodAdapter _methodAdapter; + private readonly IDiagnosticSourceMethodAdapter _methodAdapter; - public TelemetrySourceAdapter(object target) - : this(target, null, new ProxyTelemetrySourceMethodAdapter()) + public DiagnosticSourceAdapter(object target) + : this(target, null, new ProxyDiagnosticSourceMethodAdapter()) { } - public TelemetrySourceAdapter(object target, Func isEnabled) - : this(target, isEnabled, methodAdapter: new ProxyTelemetrySourceMethodAdapter()) + public DiagnosticSourceAdapter(object target, Func isEnabled) + : this(target, isEnabled, methodAdapter: new ProxyDiagnosticSourceMethodAdapter()) { } - public TelemetrySourceAdapter( + public DiagnosticSourceAdapter( object target, Func isEnabled, - ITelemetrySourceMethodAdapter methodAdapter) + IDiagnosticSourceMethodAdapter methodAdapter) { _methodAdapter = methodAdapter; @@ -42,18 +42,18 @@ namespace Microsoft.Extensions.TelemetryAdapter var methodInfos = typeInfo.DeclaredMethods; foreach (var methodInfo in methodInfos) { - var notificationNameAttribute = methodInfo.GetCustomAttribute(); - if (notificationNameAttribute != null) + var diagnosticNameAttribute = methodInfo.GetCustomAttribute(); + if (diagnosticNameAttribute != null) { var subscription = new Subscription(methodInfo); - listener.Subscriptions.Add(notificationNameAttribute.Name, subscription); + listener.Subscriptions.Add(diagnosticNameAttribute.Name, subscription); } } return listener; } - public bool IsEnabled(string telemetryName) + public bool IsEnabled(string diagnosticName) { if (_listener.Subscriptions.Count == 0) { @@ -61,11 +61,11 @@ namespace Microsoft.Extensions.TelemetryAdapter } return - _listener.Subscriptions.ContainsKey(telemetryName) && - (_listener.IsEnabled == null || _listener.IsEnabled(telemetryName)); + _listener.Subscriptions.ContainsKey(diagnosticName) && + (_listener.IsEnabled == null || _listener.IsEnabled(diagnosticName)); } - public void WriteTelemetry(string telemetryName, object parameters) + public void Write(string diagnosticName, object parameters) { if (parameters == null) { @@ -73,12 +73,12 @@ namespace Microsoft.Extensions.TelemetryAdapter } Subscription subscription; - if (!_listener.Subscriptions.TryGetValue(telemetryName, out subscription)) + if (!_listener.Subscriptions.TryGetValue(diagnosticName, out subscription)) { return; } - if (_listener.IsEnabled != null && !_listener.IsEnabled(telemetryName)) + if (_listener.IsEnabled != null && !_listener.IsEnabled(diagnosticName)) { return; } @@ -105,7 +105,7 @@ namespace Microsoft.Extensions.TelemetryAdapter void IObserver>.OnNext(KeyValuePair value) { - WriteTelemetry(value.Key, value.Value); + Write(value.Key, value.Value); } void IObserver>.OnError(Exception error) diff --git a/src/Microsoft.Extensions.TelemetryAdapter/ITelemetrySourceMethodAdapter.cs b/src/Microsoft.Extensions.DiagnosticAdapter/IDiagnosticSourceMethodAdapter.cs similarity index 74% rename from src/Microsoft.Extensions.TelemetryAdapter/ITelemetrySourceMethodAdapter.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/IDiagnosticSourceMethodAdapter.cs index b57857c..2dcd7e1 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/ITelemetrySourceMethodAdapter.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/IDiagnosticSourceMethodAdapter.cs @@ -4,9 +4,9 @@ using System; using System.Reflection; -namespace Microsoft.Extensions.TelemetryAdapter +namespace Microsoft.Extensions.DiagnosticAdapter { - public interface ITelemetrySourceMethodAdapter + public interface IDiagnosticSourceMethodAdapter { Func Adapt(MethodInfo method, Type inputType); } diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyAssembly.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyAssembly.cs similarity index 87% rename from src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyAssembly.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyAssembly.cs index 8ef34a4..e13005c 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyAssembly.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyAssembly.cs @@ -5,7 +5,7 @@ using System; using System.Reflection; using System.Reflection.Emit; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public static class ProxyAssembly { @@ -16,11 +16,11 @@ namespace Microsoft.Extensions.TelemetryAdapter.Internal static ProxyAssembly() { - var assemblyName = new AssemblyName("Microsoft.Extensions.TelemetryAdapter.ProxyAssembly"); + var assemblyName = new AssemblyName("Microsoft.Extensions.DiagnosticAdapter.ProxyAssembly"); var access = AssemblyBuilderAccess.Run; AssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, access); - ModuleBuilder = AssemblyBuilder.DefineDynamicModule("Microsoft.Extensions.TelemetryAdapter.ProxyAssembly.dll"); + ModuleBuilder = AssemblyBuilder.DefineDynamicModule("Microsoft.Extensions.DiagnosticAdapter.ProxyAssembly.dll"); } public static TypeBuilder DefineType( diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyBase.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyBase.cs similarity index 90% rename from src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyBase.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyBase.cs index 6ad159b..53b1482 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyBase.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyBase.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public abstract class ProxyBase { diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyBaseOfT.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyBaseOfT.cs similarity index 93% rename from src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyBaseOfT.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyBaseOfT.cs index d05ea4e..2448198 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyBaseOfT.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyBaseOfT.cs @@ -3,7 +3,7 @@ using System; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public class ProxyBase : ProxyBase where T : class { diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyEnumerable.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyEnumerable.cs similarity index 97% rename from src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyEnumerable.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyEnumerable.cs index e3769f6..7d21103 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyEnumerable.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyEnumerable.cs @@ -5,7 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public class ProxyEnumerable : IEnumerable { diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyList.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyList.cs similarity index 97% rename from src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyList.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyList.cs index 2df6162..fce4d9c 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyList.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyList.cs @@ -5,7 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public class ProxyList : IReadOnlyList { diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyMethodEmitter.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyMethodEmitter.cs similarity index 99% rename from src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyMethodEmitter.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyMethodEmitter.cs index 65f694b..11adc28 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyMethodEmitter.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyMethodEmitter.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Reflection; using System.Reflection.Emit; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public static class ProxyMethodEmitter { diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyTypeCache.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyTypeCache.cs similarity index 85% rename from src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyTypeCache.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyTypeCache.cs index ea6b6c6..ba3e6a2 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyTypeCache.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyTypeCache.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Concurrent; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public class ProxyTypeCache : ConcurrentDictionary, ProxyTypeCacheResult> { diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyTypeCacheResult.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyTypeCacheResult.cs similarity index 95% rename from src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyTypeCacheResult.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyTypeCacheResult.cs index 3996923..6444714 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyTypeCacheResult.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyTypeCacheResult.cs @@ -4,7 +4,7 @@ using System; using System.Reflection; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public class ProxyTypeCacheResult { diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyTypeEmitter.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyTypeEmitter.cs similarity index 99% rename from src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyTypeEmitter.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyTypeEmitter.cs index 8b00f84..d090de4 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Internal/ProxyTypeEmitter.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Internal/ProxyTypeEmitter.cs @@ -8,7 +8,7 @@ using System.Linq; using System.Reflection; using System.Reflection.Emit; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public static class ProxyTypeEmitter { diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Microsoft.Extensions.TelemetryAdapter.xproj b/src/Microsoft.Extensions.DiagnosticAdapter/Microsoft.Extensions.DiagnosticAdapter.xproj similarity index 92% rename from src/Microsoft.Extensions.TelemetryAdapter/Microsoft.Extensions.TelemetryAdapter.xproj rename to src/Microsoft.Extensions.DiagnosticAdapter/Microsoft.Extensions.DiagnosticAdapter.xproj index a626952..004df14 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Microsoft.Extensions.TelemetryAdapter.xproj +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Microsoft.Extensions.DiagnosticAdapter.xproj @@ -7,7 +7,7 @@ 87808f3c-362e-4261-aa4a-ee40ba39d64e - Microsoft.Extensions.TelemetryAdapter + Microsoft.Extensions.DiagnosticAdapter ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Properties/AssemblyInfo.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Properties/AssemblyInfo.cs similarity index 100% rename from src/Microsoft.Extensions.TelemetryAdapter/Properties/AssemblyInfo.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Properties/AssemblyInfo.cs diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Properties/Resources.Designer.cs b/src/Microsoft.Extensions.DiagnosticAdapter/Properties/Resources.Designer.cs similarity index 96% rename from src/Microsoft.Extensions.TelemetryAdapter/Properties/Resources.Designer.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/Properties/Resources.Designer.cs index e3c9599..b0f44e4 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/Properties/Resources.Designer.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/Properties/Resources.Designer.cs @@ -1,5 +1,5 @@ // -namespace Microsoft.Extensions.TelemetryAdapter +namespace Microsoft.Extensions.DiagnosticAdapter { using System.Globalization; using System.Reflection; @@ -8,7 +8,7 @@ namespace Microsoft.Extensions.TelemetryAdapter internal static class Resources { private static readonly ResourceManager _resourceManager - = new ResourceManager("Microsoft.Extensions.TelemetryAdapter.Resources", typeof(Resources).GetTypeInfo().Assembly); + = new ResourceManager("Microsoft.Extensions.DiagnosticAdapter.Resources", typeof(Resources).GetTypeInfo().Assembly); /// /// The property '{0}' on type '{1}' must define a getter to support proxy generation. diff --git a/src/Microsoft.Extensions.TelemetryAdapter/ProxyTelemetrySourceMethodAdapter.cs b/src/Microsoft.Extensions.DiagnosticAdapter/ProxyDiagnosticSourceMethodAdapter.cs similarity index 75% rename from src/Microsoft.Extensions.TelemetryAdapter/ProxyTelemetrySourceMethodAdapter.cs rename to src/Microsoft.Extensions.DiagnosticAdapter/ProxyDiagnosticSourceMethodAdapter.cs index 5a4e106..08f05a0 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/ProxyTelemetrySourceMethodAdapter.cs +++ b/src/Microsoft.Extensions.DiagnosticAdapter/ProxyDiagnosticSourceMethodAdapter.cs @@ -4,9 +4,9 @@ using System; using System.Reflection; -namespace Microsoft.Extensions.TelemetryAdapter +namespace Microsoft.Extensions.DiagnosticAdapter { - public class ProxyTelemetrySourceMethodAdapter : ITelemetrySourceMethodAdapter + public class ProxyDiagnosticSourceMethodAdapter : IDiagnosticSourceMethodAdapter { public Func Adapt(MethodInfo method, Type inputType) { diff --git a/src/Microsoft.Extensions.TelemetryAdapter/Resources.resx b/src/Microsoft.Extensions.DiagnosticAdapter/Resources.resx similarity index 100% rename from src/Microsoft.Extensions.TelemetryAdapter/Resources.resx rename to src/Microsoft.Extensions.DiagnosticAdapter/Resources.resx diff --git a/src/Microsoft.Extensions.TelemetryAdapter/project.json b/src/Microsoft.Extensions.DiagnosticAdapter/project.json similarity index 91% rename from src/Microsoft.Extensions.TelemetryAdapter/project.json rename to src/Microsoft.Extensions.DiagnosticAdapter/project.json index 38c2d5e..8aea540 100644 --- a/src/Microsoft.Extensions.TelemetryAdapter/project.json +++ b/src/Microsoft.Extensions.DiagnosticAdapter/project.json @@ -1,9 +1,9 @@ { "version": "1.0.0-*", - "description": "An TelemetryListener implementation which provides duck-typing through generated proxy types.", + "description": "A DiagnosticListener implementation which provides duck-typing through generated proxy types.", "dependencies": { "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-*", - "System.Diagnostics.Tracing.Telemetry": "4.0.0-beta-*" + "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" }, "compilationOptions": { "define": [ diff --git a/src/Microsoft.Extensions.TelemetryAdapter/TelemetryListenerExtensions.cs b/src/Microsoft.Extensions.TelemetryAdapter/TelemetryListenerExtensions.cs deleted file mode 100644 index 03c1e07..0000000 --- a/src/Microsoft.Extensions.TelemetryAdapter/TelemetryListenerExtensions.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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 Microsoft.Extensions.TelemetryAdapter; - -namespace System.Diagnostics.Tracing -{ - public static class TelemetryListenerExtensions - { - public static IDisposable SubscribeWithAdapter(this TelemetryListener telemetry, object target) - { - var adapter = new TelemetrySourceAdapter(target); - return telemetry.Subscribe(adapter, adapter.IsEnabled); - } - - public static IDisposable SubscribeWithAdapter( - this TelemetryListener telemetry, - object target, - Func isEnabled) - { - var adapter = new TelemetrySourceAdapter(target, isEnabled); - return telemetry.Subscribe(adapter, adapter.IsEnabled); - } - } -} diff --git a/test/Microsoft.Extensions.TelemetryAdapter.Test/TelemetrySourceAdapterTest.cs b/test/Microsoft.Extensions.DiagnosticAdapter.Test/DiagnosticSourceAdapterTest.cs similarity index 85% rename from test/Microsoft.Extensions.TelemetryAdapter.Test/TelemetrySourceAdapterTest.cs rename to test/Microsoft.Extensions.DiagnosticAdapter.Test/DiagnosticSourceAdapterTest.cs index 8db6bd9..79329b1 100644 --- a/test/Microsoft.Extensions.TelemetryAdapter.Test/TelemetrySourceAdapterTest.cs +++ b/test/Microsoft.Extensions.DiagnosticAdapter.Test/DiagnosticSourceAdapterTest.cs @@ -4,15 +4,15 @@ using System; using Xunit; -namespace Microsoft.Extensions.TelemetryAdapter +namespace Microsoft.Extensions.DiagnosticAdapter { - public class TelemetrySourceAdapterTest + public class DiagnosticSourceAdapterTest { public class OneTarget { public int OneCallCount { get; private set; } - [TelemetryName("One")] + [DiagnosticName("One")] public void One() { ++OneCallCount; @@ -78,7 +78,7 @@ namespace Microsoft.Extensions.TelemetryAdapter } [Fact] - public void CallingWriteTelemetryWillInvokeMethod() + public void CallingWriteWillInvokeMethod() { // Arrange var target = new OneTarget(); @@ -86,12 +86,12 @@ namespace Microsoft.Extensions.TelemetryAdapter // Act & Assert Assert.Equal(0, target.OneCallCount); - adapter.WriteTelemetry("One", new { }); + adapter.Write("One", new { }); Assert.Equal(1, target.OneCallCount); } [Fact] - public void CallingWriteTelemetryForNonEnlistedNameIsHarmless() + public void CallingWriteForNonEnlistedNameIsHarmless() { // Arrange var target = new OneTarget(); @@ -99,12 +99,12 @@ namespace Microsoft.Extensions.TelemetryAdapter // Act & Assert Assert.Equal(0, target.OneCallCount); - adapter.WriteTelemetry("Two", new { }); + adapter.Write("Two", new { }); Assert.Equal(0, target.OneCallCount); } [Fact] - public void WriteTelemetry_True_CallsIsEnabled() + public void Write_True_CallsIsEnabled() { // Arrange var callCount = 0; @@ -119,7 +119,7 @@ namespace Microsoft.Extensions.TelemetryAdapter var adapter = CreateAdapter(target, isEnabled); // Act - adapter.WriteTelemetry("One", new { }); + adapter.Write("One", new { }); // Assert Assert.Equal(1, callCount); @@ -127,7 +127,7 @@ namespace Microsoft.Extensions.TelemetryAdapter } [Fact] - public void WriteTelemetry_False_CallsIsEnabled() + public void Write_False_CallsIsEnabled() { // Arrange var callCount = 0; @@ -142,7 +142,7 @@ namespace Microsoft.Extensions.TelemetryAdapter var adapter = CreateAdapter(target, isEnabled); // Act - adapter.WriteTelemetry("One", new { }); + adapter.Write("One", new { }); // Assert Assert.Equal(1, callCount); @@ -155,7 +155,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public string Beta { get; private set; } public int Delta { get; private set; } - [TelemetryName("Two")] + [DiagnosticName("Two")] public void Two(string alpha, string beta, int delta) { Alpha = alpha; @@ -172,7 +172,7 @@ namespace Microsoft.Extensions.TelemetryAdapter var adapter = CreateAdapter(target); // Act - adapter.WriteTelemetry("Two", new { alpha = "ALPHA", beta = "BETA", delta = -1 }); + adapter.Write("Two", new { alpha = "ALPHA", beta = "BETA", delta = -1 }); // Assert Assert.Equal("ALPHA", target.Alpha); @@ -188,7 +188,7 @@ namespace Microsoft.Extensions.TelemetryAdapter var adapter = CreateAdapter(target); // Act - adapter.WriteTelemetry("Two", new { alpha = "ALPHA", beta = "BETA", delta = -1, extra = this }); + adapter.Write("Two", new { alpha = "ALPHA", beta = "BETA", delta = -1, extra = this }); // Assert Assert.Equal("ALPHA", target.Alpha); @@ -204,7 +204,7 @@ namespace Microsoft.Extensions.TelemetryAdapter var adapter = CreateAdapter(target); // Act - adapter.WriteTelemetry("Two", new { alpha = "ALPHA", delta = -1 }); + adapter.Write("Two", new { alpha = "ALPHA", delta = -1 }); // Assert Assert.Equal("ALPHA", target.Alpha); @@ -213,14 +213,14 @@ namespace Microsoft.Extensions.TelemetryAdapter } [Fact] - public void WriteTelemetryCanDuckType() + public void WriteCanDuckType() { // Arrange var target = new ThreeTarget(); var adapter = CreateAdapter(target); // Act - adapter.WriteTelemetry("Three", new + adapter.Write("Three", new { person = new Person { @@ -242,14 +242,14 @@ namespace Microsoft.Extensions.TelemetryAdapter } [Fact] - public void WriteTelemetry_NominialType() + public void Write_NominialType() { // Arrange var target = new ThreeTarget(); var adapter = CreateAdapter(target); // Act - adapter.WriteTelemetry("Three", new NominalType() + adapter.Write("Three", new NominalType() { Person = new Person { @@ -274,7 +274,7 @@ namespace Microsoft.Extensions.TelemetryAdapter { public IPerson Person { get; private set; } - [TelemetryName("Three")] + [DiagnosticName("Three")] public void Three(IPerson person) { Person = person; @@ -329,9 +329,9 @@ namespace Microsoft.Extensions.TelemetryAdapter public int Value { get; private set; } } - private static TelemetrySourceAdapter CreateAdapter(object target, Func isEnabled = null) + private static DiagnosticSourceAdapter CreateAdapter(object target, Func isEnabled = null) { - return new TelemetrySourceAdapter(target, isEnabled, new ProxyTelemetrySourceMethodAdapter()); + return new DiagnosticSourceAdapter(target, isEnabled, new ProxyDiagnosticSourceMethodAdapter()); } } } diff --git a/test/Microsoft.Extensions.TelemetryAdapter.Test/Internal/ProxyTypeEmitterTest.cs b/test/Microsoft.Extensions.DiagnosticAdapter.Test/Internal/ProxyTypeEmitterTest.cs similarity index 99% rename from test/Microsoft.Extensions.TelemetryAdapter.Test/Internal/ProxyTypeEmitterTest.cs rename to test/Microsoft.Extensions.DiagnosticAdapter.Test/Internal/ProxyTypeEmitterTest.cs index 2b76375..8378cf3 100644 --- a/test/Microsoft.Extensions.TelemetryAdapter.Test/Internal/ProxyTypeEmitterTest.cs +++ b/test/Microsoft.Extensions.DiagnosticAdapter.Test/Internal/ProxyTypeEmitterTest.cs @@ -7,7 +7,7 @@ using System.Linq; using Microsoft.AspNet.Testing.xunit; using Xunit; -namespace Microsoft.Extensions.TelemetryAdapter.Internal +namespace Microsoft.Extensions.DiagnosticAdapter.Internal { public class ProxyTypeEmitterTest { diff --git a/test/Microsoft.Extensions.TelemetryAdapter.Test/Microsoft.Extensions.TelemetryAdapter.Test.xproj b/test/Microsoft.Extensions.DiagnosticAdapter.Test/Microsoft.Extensions.DiagnosticAdapter.Test.xproj similarity index 77% rename from test/Microsoft.Extensions.TelemetryAdapter.Test/Microsoft.Extensions.TelemetryAdapter.Test.xproj rename to test/Microsoft.Extensions.DiagnosticAdapter.Test/Microsoft.Extensions.DiagnosticAdapter.Test.xproj index 31d38dd..5566cd2 100644 --- a/test/Microsoft.Extensions.TelemetryAdapter.Test/Microsoft.Extensions.TelemetryAdapter.Test.xproj +++ b/test/Microsoft.Extensions.DiagnosticAdapter.Test/Microsoft.Extensions.DiagnosticAdapter.Test.xproj @@ -1,4 +1,4 @@ - + 14.0 @@ -6,16 +6,14 @@ - fb993eee-ff13-4454-bf49-f60dd0a531f7 - Microsoft.Extensions.TelemetryAdapter.Test + 02754747-c385-4662-ad58-49ce54c3d7af + Microsoft.Extensions.DiagnosticAdapter.Test ..\..\artifacts\obj\$(MSBuildProjectName) ..\..\artifacts\bin\$(MSBuildProjectName)\ + 2.0 - - - \ No newline at end of file diff --git a/test/Microsoft.Extensions.TelemetryAdapter.Test/ProxyTelemetrySourceMethodAdapterTest.cs b/test/Microsoft.Extensions.DiagnosticAdapter.Test/ProxyDiagnosticSourceMethodAdapterTest.cs similarity index 90% rename from test/Microsoft.Extensions.TelemetryAdapter.Test/ProxyTelemetrySourceMethodAdapterTest.cs rename to test/Microsoft.Extensions.DiagnosticAdapter.Test/ProxyDiagnosticSourceMethodAdapterTest.cs index 541d3f4..09c7ea4 100644 --- a/test/Microsoft.Extensions.TelemetryAdapter.Test/ProxyTelemetrySourceMethodAdapterTest.cs +++ b/test/Microsoft.Extensions.DiagnosticAdapter.Test/ProxyDiagnosticSourceMethodAdapterTest.cs @@ -6,15 +6,15 @@ using System.Linq.Expressions; using System.Reflection; using Xunit; -namespace Microsoft.Extensions.TelemetryAdapter +namespace Microsoft.Extensions.DiagnosticAdapter { - public class ProxyTelemetrySourceMethodAdapterTest + public class ProxyTDiagnosticSourceMethodAdapterTest { [Fact] public void Adapt_Throws_ForSameNamedPropertiesWithDifferentCasing() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener1(); var method = GetMethodInfo(l => l.Listen(5, "joey")); @@ -36,7 +36,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public void Adapt_ReturnsTrueForTypeMatch() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener1(); var method = GetMethodInfo(l => l.Listen()); @@ -52,7 +52,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public void Adapt_ReturnsFalseForTypeNotMatching() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener1(); var method = GetMethodInfo(l => l.Listen()); @@ -68,7 +68,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public void Adapt_SplatsParameters() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener2(); var value = new { id = 17, name = "Bill" }; @@ -87,7 +87,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public void Adapt_SplatsParameters_CamelCase() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener4(); var value = new { Id = 17, Person = new Person() { Name = "Bill" } }; @@ -106,7 +106,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public void Adapt_SplatsParameters_CaseInsensitive() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener4(); var value = new { ID = 17, PersOn = new Person() { Name = "Bill" }}; @@ -125,7 +125,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public void Adapt_SplatsParameters_ExtraEventDataIgnored() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener2(); var value = new { id = 17, name = "Bill", ignored = "hi" }; @@ -144,7 +144,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public void Adapt_SplatsParameters_ExtraParametersGetDefaultValues() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener2(); var value = new { }; @@ -163,7 +163,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public void Adapt_SplatsParameters_WithProxy() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener3(); var value = new { id = 17, person = new Person() { Name = "Bill" } }; @@ -182,7 +182,7 @@ namespace Microsoft.Extensions.TelemetryAdapter public void Adapt_SplatsParameters_WithNominalType() { // Arrange - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var listener = new Listener3(); var value = new NominalType() { Id = 17, Person = new Person() { Name = "Bill" } }; @@ -207,7 +207,7 @@ namespace Microsoft.Extensions.TelemetryAdapter var targetMethodInfo = target.GetType().GetMethod(nameof(Listener5.TargetMethod)); // Act - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var callback = adapter.Adapt(targetMethodInfo, source.GetType()); var result = callback(target, source); @@ -228,7 +228,7 @@ namespace Microsoft.Extensions.TelemetryAdapter var targetMethodInfo = target.GetType().GetMethod(nameof(Listener6.Listen)); // Act - var adapter = new ProxyTelemetrySourceMethodAdapter(); + var adapter = new ProxyDiagnosticSourceMethodAdapter(); var callback = adapter.Adapt(targetMethodInfo, source.GetType()); var result = callback(target, source); diff --git a/test/Microsoft.Extensions.TelemetryAdapter.Test/project.json b/test/Microsoft.Extensions.DiagnosticAdapter.Test/project.json similarity index 67% rename from test/Microsoft.Extensions.TelemetryAdapter.Test/project.json rename to test/Microsoft.Extensions.DiagnosticAdapter.Test/project.json index 9243aa0..7e06811 100644 --- a/test/Microsoft.Extensions.TelemetryAdapter.Test/project.json +++ b/test/Microsoft.Extensions.DiagnosticAdapter.Test/project.json @@ -1,10 +1,9 @@ { "dependencies": { "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Extensions.TelemetryAdapter": "1.0.0-*", + "Microsoft.Extensions.DiagnosticAdapter": "1.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, - "compile": "../../src/Microsoft.Extensions.TelemetryAdapter/ReflectionTelemetrySourceMethodAdapter.cs", "compilationOptions": {"define": ["TEST"]}, "commands": { "run": "xunit.runner.aspnet",