diff --git a/Logging.sln b/Logging.sln index 54230689..b454b8a2 100644 --- a/Logging.sln +++ b/Logging.sln @@ -57,6 +57,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiagnosticSourceListener.ne EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldTest", "HelloWorldTest\HelloWorldTest.csproj", "{7AAF876A-43B5-4F47-B402-DC5C94948F3F}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TraceListener.netcoreapp10.Tests", "test\TraceListener.netcoreapp10.Tests\TraceListener.netcoreapp10.Tests.csproj", "{11E4A92F-154E-450B-8508-437C28744BC2}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution test\CommonTestShared\CommonTestShared.projitems*{3b9ab7fa-562d-4e4e-86e3-3348426bc0d9}*SharedItemsImports = 13 @@ -195,6 +197,14 @@ Global {7AAF876A-43B5-4F47-B402-DC5C94948F3F}.Release|Any CPU.Build.0 = Release|Any CPU {7AAF876A-43B5-4F47-B402-DC5C94948F3F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {7AAF876A-43B5-4F47-B402-DC5C94948F3F}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {11E4A92F-154E-450B-8508-437C28744BC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11E4A92F-154E-450B-8508-437C28744BC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11E4A92F-154E-450B-8508-437C28744BC2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {11E4A92F-154E-450B-8508-437C28744BC2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {11E4A92F-154E-450B-8508-437C28744BC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11E4A92F-154E-450B-8508-437C28744BC2}.Release|Any CPU.Build.0 = Release|Any CPU + {11E4A92F-154E-450B-8508-437C28744BC2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {11E4A92F-154E-450B-8508-437C28744BC2}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -218,6 +228,7 @@ Global {A964DE6D-9750-4013-8BE2-79C2AFC056E5} = {EE933574-C82B-4E59-A0D1-05328197B937} {625DABF6-C4AD-41A9-B2C0-04C9FEC2ADCF} = {2FCC45B3-D820-405D-87FA-467C96465BB1} {7AAF876A-43B5-4F47-B402-DC5C94948F3F} = {2FCC45B3-D820-405D-87FA-467C96465BB1} + {11E4A92F-154E-450B-8508-437C28744BC2} = {2FCC45B3-D820-405D-87FA-467C96465BB1} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AC8888B1-0E98-49D7-BE15-EB97A6261C0D} diff --git a/src/TraceListener/AssemblyInfo.cs b/src/TraceListener/AssemblyInfo.cs index 351764f8..f8082cd3 100644 --- a/src/TraceListener/AssemblyInfo.cs +++ b/src/TraceListener/AssemblyInfo.cs @@ -31,6 +31,7 @@ [assembly: Guid("3aada9bf-fc15-42fd-ace5-4cb2f11c1f2a")] [assembly: InternalsVisibleTo("Microsoft.ApplicationInsights.TraceListener.Net45.Tests, PublicKey=" + AssemblyInfo.PublicKey)] +[assembly: InternalsVisibleTo("Microsoft.ApplicationInsights.TraceListener.NetCoreApp10.Tests, PublicKey=" + AssemblyInfo.PublicKey)] internal static class AssemblyInfo { diff --git a/src/TraceListener/TraceListener.csproj b/src/TraceListener/TraceListener.csproj index dc9e60d0..642be751 100644 --- a/src/TraceListener/TraceListener.csproj +++ b/src/TraceListener/TraceListener.csproj @@ -9,7 +9,7 @@ false false - net45 + net45;netstandard1.3 Microsoft.ApplicationInsights.TraceListener Microsoft.ApplicationInsights.TraceListener @@ -41,6 +41,10 @@ + + + + diff --git a/test/Shared/AdapterHelper.cs b/test/Shared/AdapterHelper.cs index 9391df65..049307c1 100644 --- a/test/Shared/AdapterHelper.cs +++ b/test/Shared/AdapterHelper.cs @@ -11,6 +11,7 @@ namespace Microsoft.ApplicationInsights.Tracing.Tests using System.Reflection; using System.Threading; using Microsoft.ApplicationInsights.Channel; + using Microsoft.ApplicationInsights.Extensibility; using Microsoft.VisualStudio.TestTools.UnitTesting; public class AdapterHelper : IDisposable @@ -20,15 +21,13 @@ public class AdapterHelper : IDisposable #if NET45 || NET46 private static readonly string ApplicationInsightsConfigFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ApplicationInsights.config"); -#else - private static readonly string ApplicationInsightsConfigFilePath = - Path.Combine(Path.GetDirectoryName(typeof(AdapterHelper).GetTypeInfo().Assembly.Location), "ApplicationInsights.config"); #endif public AdapterHelper(string instrumentationKey = "F8474271-D231-45B6-8DD4-D344C309AE69") { this.InstrumentationKey = instrumentationKey; - + +#if NET45 || NET46 string configuration = string.Format( @" @@ -37,6 +36,10 @@ public AdapterHelper(string instrumentationKey = "F8474271-D231-45B6-8DD4-D344C3 instrumentationKey); File.WriteAllText(ApplicationInsightsConfigFilePath, configuration); +#else + TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey; +#endif + this.Channel = new CustomTelemetryChannel(); } @@ -82,10 +85,12 @@ private void Dispose(bool dispossing) { this.Channel.Dispose(); +#if NET45 || NET46 if (File.Exists(ApplicationInsightsConfigFilePath)) { File.Delete(ApplicationInsightsConfigFilePath); } +#endif } } } diff --git a/test/TraceListener.Net45.Tests/ApplicationInsightsTraceFilterTests.cs b/test/Shared/ApplicationInsightsTraceFilterTests.cs similarity index 88% rename from test/TraceListener.Net45.Tests/ApplicationInsightsTraceFilterTests.cs rename to test/Shared/ApplicationInsightsTraceFilterTests.cs index 76ac94b3..1d6eaa5e 100644 --- a/test/TraceListener.Net45.Tests/ApplicationInsightsTraceFilterTests.cs +++ b/test/Shared/ApplicationInsightsTraceFilterTests.cs @@ -102,12 +102,5 @@ private void TraceFilterTestHelper( Assert.AreEqual(shouldTrace, this.adapterHelper.Channel.SentItems.Length == 1); } } - - private Tuple LookupTraceFiterExpections(bool? expectationOverride = null) - { - TraceEventType eventType = (TraceEventType)Enum.Parse(typeof(TraceEventType), (string)this.TestContext.DataRow["TraceEventType"]); - bool expect = bool.Parse((string)this.TestContext.DataRow["Expect"]); - return new Tuple(eventType, expectationOverride.HasValue == true ? expectationOverride.Value : expect); - } } } diff --git a/test/TraceListener.Net45.Tests/ApplicationInsightsTraceListenerTests.cs b/test/Shared/ApplicationInsightsTraceListenerTests.cs similarity index 98% rename from test/TraceListener.Net45.Tests/ApplicationInsightsTraceListenerTests.cs rename to test/Shared/ApplicationInsightsTraceListenerTests.cs index b55d4040..be5975bb 100644 --- a/test/TraceListener.Net45.Tests/ApplicationInsightsTraceListenerTests.cs +++ b/test/Shared/ApplicationInsightsTraceListenerTests.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; using System.Linq; + using System.Reflection; using Microsoft.ApplicationInsights.CommonTestShared; using Microsoft.ApplicationInsights.DataContracts; using Microsoft.ApplicationInsights.Extensibility; @@ -202,6 +203,7 @@ public void TraceListenerStoresDataItemsConvertedToStringInTraceMessage() Assert.AreEqual(expectedEventId.ToString(), telemetry.Properties["EventId"]); } +#if NET45 [TestMethod] [TestCategory("TraceListener")] public void TraceListenerSendsResumeAsVerbose() @@ -266,6 +268,7 @@ public void TraceListenerSendsTransferAsVerbose() TraceTelemetry telemetry = (TraceTelemetry)this.adapterHelper.Channel.SentItems.FirstOrDefault(); Assert.AreEqual(SeverityLevel.Verbose, telemetry.SeverityLevel); } +#endif [TestMethod] [TestCategory("TraceListener")] @@ -340,6 +343,7 @@ public void TraceEventDoesNotThrowArgumentNullExceptionWhenArgsIsNull() source.TraceInformation("TestMessage"); } +#if NET45 [TestMethod] public void TraceEventDoesNotStoreLogicalOperationStackInTelemetryPropertiesBecauseLongValuesAreRejected() { @@ -366,6 +370,7 @@ public void TraceEventDoesNotStoreCallStackInTelemetryPropertiesBecauseLongValue var telemetry = (TraceTelemetry)this.adapterHelper.Channel.SentItems.Single(); Assert.IsFalse(telemetry.Properties.ContainsKey("CallStack")); } +#endif [TestMethod] public void TraceListenerFlushesChannel() @@ -397,10 +402,14 @@ private void ValidateASingleMessageActionBased( { listener.TraceOutputOptions = options; TraceEventCache traceEventCache = new TraceEventCache(); +#if NET45 PrivateObject privateObject = new PrivateObject(traceEventCache); privateObject.SetField("timeStamp", DateTime.Now.Ticks); privateObject.SetField("stackTrace", "Environment.StackTrace"); - +#else + TypeInfo traceEventCacheType = traceEventCache.GetType().GetTypeInfo(); + traceEventCacheType.GetDeclaredField("_timeStamp").SetValue(traceEventCache, DateTime.Now.Ticks); +#endif callTraceAction(listener, traceEventCache); TraceTelemetry telemetry = (TraceTelemetry)this.adapterHelper.Channel.SentItems.FirstOrDefault(); diff --git a/test/TraceListener.Net45.Tests/TraceListener.Net45.Tests.csproj b/test/TraceListener.Net45.Tests/TraceListener.Net45.Tests.csproj index a3739959..a127776e 100644 --- a/test/TraceListener.Net45.Tests/TraceListener.Net45.Tests.csproj +++ b/test/TraceListener.Net45.Tests/TraceListener.Net45.Tests.csproj @@ -7,6 +7,11 @@ false + + + + + diff --git a/test/TraceListener.Net45.Tests/packages.config b/test/TraceListener.Net45.Tests/packages.config deleted file mode 100644 index 59efec9e..00000000 --- a/test/TraceListener.Net45.Tests/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/test/TraceListener.netcoreapp10.Tests/TraceListener.netcoreapp10.Tests.csproj b/test/TraceListener.netcoreapp10.Tests/TraceListener.netcoreapp10.Tests.csproj new file mode 100644 index 00000000..24b6963d --- /dev/null +++ b/test/TraceListener.netcoreapp10.Tests/TraceListener.netcoreapp10.Tests.csproj @@ -0,0 +1,42 @@ + + + + Microsoft.ApplicationInsights.TraceListener.Tests + Microsoft.ApplicationInsights.TraceListener.NetCoreApp10.Tests + netcoreapp1.0 + false + false + + + + + + + + + + + + + + All + + + + + + + + + + + + + + + + + + + +