Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Logging.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
1 change: 1 addition & 0 deletions src/TraceListener/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.Tests, PublicKey=" + AssemblyInfo.PublicKey)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe have netcoreapp10 in the name of test assembly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


internal static class AssemblyInfo
{
Expand Down
6 changes: 5 additions & 1 deletion src/TraceListener/TraceListener.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>

<TargetFrameworks>net45</TargetFrameworks>
<TargetFrameworks>net45;netstandard1.3</TargetFrameworks>

<RootNamespace>Microsoft.ApplicationInsights.TraceListener</RootNamespace>
<AssemblyName>Microsoft.ApplicationInsights.TraceListener</AssemblyName>
Expand Down Expand Up @@ -41,6 +41,10 @@
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
<PackageReference Include="System.Diagnostics.TraceSource" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<Content Include="app.config.install.xdt" />
<Content Include="app.config.uninstall.xdt" />
Expand Down
13 changes: 9 additions & 4 deletions test/Shared/AdapterHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ApplicationInsights xmlns=""http://schemas.microsoft.com/ApplicationInsights/2013/Settings"">
Expand All @@ -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();
}

Expand Down Expand Up @@ -82,10 +85,12 @@ private void Dispose(bool dispossing)
{
this.Channel.Dispose();

#if NET45 || NET46
if (File.Exists(ApplicationInsightsConfigFilePath))
{
File.Delete(ApplicationInsightsConfigFilePath);
}
#endif
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,5 @@ private void TraceFilterTestHelper(
Assert.AreEqual(shouldTrace, this.adapterHelper.Channel.SentItems.Length == 1);
}
}

private Tuple<TraceEventType, bool> 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<TraceEventType, bool>(eventType, expectationOverride.HasValue == true ? expectationOverride.Value : expect);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -202,6 +203,7 @@ public void TraceListenerStoresDataItemsConvertedToStringInTraceMessage()
Assert.AreEqual(expectedEventId.ToString(), telemetry.Properties["EventId"]);
}

#if NET45
[TestMethod]
[TestCategory("TraceListener")]
public void TraceListenerSendsResumeAsVerbose()
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -340,6 +343,7 @@ public void TraceEventDoesNotThrowArgumentNullExceptionWhenArgsIsNull()
source.TraceInformation("TestMessage");
}

#if NET45
[TestMethod]
public void TraceEventDoesNotStoreLogicalOperationStackInTelemetryPropertiesBecauseLongValuesAreRejected()
{
Expand All @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Microsoft.ApplicationInsights.TraceListener.Tests</RootNamespace>
<AssemblyName>Microsoft.ApplicationInsights.TraceListener.Tests</AssemblyName>
<TargetFramework>netcoreapp1.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\TraceListener.Net45.Tests\ApplicationInsightsTraceFilterTests.cs" Link="ApplicationInsightsTraceFilterTests.cs" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving thos to the folder with the name Shared can make folders structure cleaner. Can you do it please?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<Compile Include="..\TraceListener.Net45.Tests\ApplicationInsightsTraceListenerTests.cs" Link="ApplicationInsightsTraceListenerTests.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.6.0-beta2" />
<PackageReference Include="Microbuild.Core" Version="0.2.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Diagnostics.TraceSource" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\TraceListener\TraceListener.csproj" />
</ItemGroup>

<ItemGroup>
<!-- Identifies the project as test project -->
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'Test.props'))\Test.props" />

<Import Project="..\Shared\Adapters.Shared.Tests.projitems" Label="Shared" Condition="Exists('..\Shared\Adapters.Shared.Tests.projitems')" />
<Import Project="..\CommonTestShared\CommonTestShared.projitems" Label="Shared" Condition="Exists('..\CommonTestShared\CommonTestShared.projitems')" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), 'Common.targets'))\Common.targets" />

</Project>