Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

ILogger - Exception.Message is populated as ExceptionTelemetry.Message, Bump version #282

Merged
merged 6 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
### Version 2.10.0-beta4
- Update Base SDK to version 2.10.0-beta4
- [ILogger - If an exception is passed to log, then Exception.Message is populated as ExceptionTelemetry.Message. If TrackExceptionsAsExceptionTelemetry is false, then Exception.Message is stored as custom property "ExceptionMessage"](https://github.com/Microsoft/ApplicationInsights-dotnet-logging/pull/282)

### Version 2.9.1
- Update Base SDK to version 2.9.1

Expand Down
6 changes: 3 additions & 3 deletions GlobalStaticVersion.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
Update for every public release.
-->
<SemanticVersionMajor>2</SemanticVersionMajor>
<SemanticVersionMinor>9</SemanticVersionMinor>
<SemanticVersionPatch>1</SemanticVersionPatch>
<PreReleaseMilestone></PreReleaseMilestone>
<SemanticVersionMinor>10</SemanticVersionMinor>
<SemanticVersionPatch>0</SemanticVersionPatch>
<PreReleaseMilestone>beta4</PreReleaseMilestone>
<!--
Date when Semantic Version was changed.
Update for every public release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/EtwCollector/EtwCollector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<PackageReference Include="Microsoft.Diagnostics.Tracing.EventRegister" Version="1.1.28">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="1.0.41" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/EventSourceListener/EventSourceListener.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/EventSourceListener/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a539bb1d-29ff-48e8-8d6e-dfcc543dc2b4")]

[assembly: InternalsVisibleTo("Microsoft.ApplicationInsights.EventSourceListener.Tests, PublicKey=" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("Microsoft.ApplicationInsights.EventSourceListener.NetCoreApp10.Tests, PublicKey=" + AssemblyInfo.PublicKey)]

internal static class AssemblyInfo
{
Expand Down
8 changes: 7 additions & 1 deletion src/ILogger/ApplicationInsightsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,22 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
formatter(state, exception),
ApplicationInsightsLogger.GetSeverityLevel(logLevel));
this.PopulateTelemetry(traceTelemetry, state, eventId);
if (exception != null)
{
traceTelemetry.Properties.Add("ExceptionMessage", exception.Message);
}

this.telemetryClient.TrackTrace(traceTelemetry);
}
else
{
ExceptionTelemetry exceptionTelemetry = new ExceptionTelemetry(exception)
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
{
Message = formatter(state, exception),
Message = exception.Message,
SeverityLevel = ApplicationInsightsLogger.GetSeverityLevel(logLevel),
};

exceptionTelemetry.Properties.Add("FormattedMessage", formatter(state, exception));
this.PopulateTelemetry(exceptionTelemetry, state, eventId);
this.telemetryClient.TrackException(exceptionTelemetry);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ILogger/ILogger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/Log4NetAppender/Log4NetAppender.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PackageReference Include="Microsoft.Diagnostics.Tracing.EventRegister" Version="1.1.28">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
Expand Down
2 changes: 1 addition & 1 deletion src/NLogTarget/NLogTarget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<PackageReference Include="Microsoft.Diagnostics.Tracing.EventRegister" Version="1.1.28">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
Expand Down
2 changes: 1 addition & 1 deletion src/TraceListener/TraceListener.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.Diagnostics.Tracing.EventRegister" Version="1.1.28">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<RootNamespace>Microsoft.ApplicationInsights.DiagnosticSourceListener.Tests</RootNamespace>
<AssemblyName>Microsoft.ApplicationInsights.DiagnosticSourceListener.Tests</AssemblyName>
<AssemblyName>Microsoft.ApplicationInsights.DiagnosticSourceListener.NetCoreApp10.Tests</AssemblyName>
<TargetFramework>netcoreapp1.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
Expand All @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="1.0.41" />
<ProjectReference Include="..\..\src\EtwCollector\EtwCollector.csproj" />
<Reference Include="System.Net.Http" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.ApplicationInsights.EventSourceListener.Tests</RootNamespace>
<AssemblyName>Microsoft.ApplicationInsights.EventSourceListener.Tests</AssemblyName>
<AssemblyName>Microsoft.ApplicationInsights.EventSourceListener.NetCoreApp10.Tests</AssemblyName>
<TargetFramework>netcoreapp1.0</TargetFramework>
<FileAlignment>512</FileAlignment>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand All @@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 14 additions & 10 deletions test/ILogger.NetStandard.Tests/ILoggerIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void ApplicationInsightsLoggerIsInvokedWhenUsingILogger()
ILogger<ILoggerIntegrationTests> testLogger = serviceProvider.GetRequiredService<ILogger<ILoggerIntegrationTests>>();

testLogger.LogInformation("Testing");
testLogger.LogError(new Exception("TestException"), "Exception");
testLogger.LogError(new Exception("ExceptionMessage"), "LoggerMessage");
testLogger.LogInformation(new EventId(100, "TestEvent"), "TestingEvent");
testLogger.LogCritical("Critical");
testLogger.LogTrace("Trace");
Expand All @@ -65,7 +65,8 @@ public void ApplicationInsightsLoggerIsInvokedWhenUsingILogger()
Assert.AreEqual(SeverityLevel.Verbose, (itemsReceived[6] as TraceTelemetry).SeverityLevel);

Assert.AreEqual("Testing", (itemsReceived[0] as TraceTelemetry).Message);
Assert.AreEqual("Exception", (itemsReceived[1] as ExceptionTelemetry).Message);
Assert.AreEqual("ExceptionMessage", (itemsReceived[1] as ExceptionTelemetry).Message);
Assert.AreEqual("LoggerMessage", (itemsReceived[1] as ExceptionTelemetry).Properties["FormattedMessage"]);
Assert.AreEqual("TestingEvent", (itemsReceived[2] as TraceTelemetry).Message);
Assert.AreEqual("Critical", (itemsReceived[3] as TraceTelemetry).Message);
Assert.AreEqual("Trace", (itemsReceived[4] as TraceTelemetry).Message);
Expand All @@ -92,13 +93,14 @@ public void ApplicationInsightsLoggerLogsExceptionAsExceptionWhenSwitchIsTrue()
ILogger<ILoggerIntegrationTests> testLogger = serviceProvider.GetRequiredService<ILogger<ILoggerIntegrationTests>>();

testLogger.LogInformation("Testing");
testLogger.LogError(new Exception("TestException"), "Exception");
testLogger.LogError(new Exception("ExceptionMessage"), "LoggerMessage");

Assert.IsInstanceOfType(itemsReceived[0], typeof(TraceTelemetry));
Assert.IsInstanceOfType(itemsReceived[1], typeof(ExceptionTelemetry));

Assert.AreEqual("Testing", (itemsReceived[0] as TraceTelemetry).Message);
Assert.AreEqual("Exception", (itemsReceived[1] as ExceptionTelemetry).Message);
Assert.AreEqual("ExceptionMessage", (itemsReceived[1] as ExceptionTelemetry).Message);
Assert.AreEqual("LoggerMessage", (itemsReceived[1] as ExceptionTelemetry).Properties["FormattedMessage"]);
}

/// <summary>
Expand All @@ -119,7 +121,7 @@ public void ApplicationInsightsLoggerLogsExceptionAsTraceWhenSwitchIsFalse()
ILogger<ILoggerIntegrationTests> testLogger = serviceProvider.GetRequiredService<ILogger<ILoggerIntegrationTests>>();

testLogger.LogInformation("Testing");
testLogger.LogError(new Exception("TestException"), "Exception");
testLogger.LogError(new Exception("ExceptionMessage"), "LoggerMessage");

Assert.IsInstanceOfType(itemsReceived[0], typeof(TraceTelemetry));
Assert.IsInstanceOfType(itemsReceived[1], typeof(TraceTelemetry));
Expand All @@ -128,7 +130,9 @@ public void ApplicationInsightsLoggerLogsExceptionAsTraceWhenSwitchIsFalse()
Assert.AreEqual("Testing", (itemsReceived[0] as TraceTelemetry).Message);

Assert.AreEqual(SeverityLevel.Error, (itemsReceived[1] as TraceTelemetry).SeverityLevel);
Assert.AreEqual("Exception", (itemsReceived[1] as TraceTelemetry).Message);
Assert.AreEqual("LoggerMessage", (itemsReceived[1] as TraceTelemetry).Message);

Assert.AreEqual("ExceptionMessage", (itemsReceived[1] as TraceTelemetry).Properties["ExceptionMessage"]);
}

/// <summary>
Expand All @@ -154,7 +158,7 @@ public void ApplicationInsightsLoggerAddsScopeWhenSwitchIsTrue()
using (testLogger.BeginScope<IReadOnlyCollection<KeyValuePair<string, object>>>(new Dictionary<string, object> { { "Key", "Value" } }))
{
testLogger.LogInformation("Testing");
testLogger.LogError(new Exception("TestException"), "Exception");
testLogger.LogError(new Exception("ExceptionMessage"), "LoggerMessage");
}
}

Expand All @@ -165,7 +169,7 @@ public void ApplicationInsightsLoggerAddsScopeWhenSwitchIsTrue()
Assert.AreEqual("Value", (itemsReceived[1] as ISupportProperties).Properties["Key"]);

Assert.AreEqual("Testing", (itemsReceived[0] as TraceTelemetry).Message);
Assert.AreEqual("Exception", (itemsReceived[1] as ExceptionTelemetry).Message);
Assert.AreEqual("ExceptionMessage", (itemsReceived[1] as ExceptionTelemetry).Message);
}

/// <summary>
Expand All @@ -191,7 +195,7 @@ public void ApplicationInsightsLoggerDoesNotAddScopeWhenSwitchIsFalse()
using (testLogger.BeginScope<IReadOnlyCollection<KeyValuePair<string, object>>>(new Dictionary<string, object> { { "Key", "Value" } }))
{
testLogger.LogInformation("Testing");
testLogger.LogError(new Exception("TestException"), "Exception");
testLogger.LogError(new Exception("ExceptionMessage"), "LoggerMessage");
}
}

Expand All @@ -202,7 +206,7 @@ public void ApplicationInsightsLoggerDoesNotAddScopeWhenSwitchIsFalse()
Assert.IsFalse((itemsReceived[1] as ISupportProperties).Properties.ContainsKey("Key"));

Assert.AreEqual("Testing", (itemsReceived[0] as TraceTelemetry).Message);
Assert.AreEqual("Exception", (itemsReceived[1] as ExceptionTelemetry).Message);
Assert.AreEqual("ExceptionMessage", (itemsReceived[1] as ExceptionTelemetry).Message);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="log4net" Version="2.0.7" />
<ProjectReference Include="..\..\src\Log4NetAppender\Log4NetAppender.csproj" />
<Reference Include="System.Net.Http" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="log4net" Version="2.0.8" />
<ProjectReference Include="..\..\src\Log4NetAppender\Log4NetAppender.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/NLogTarget.Net45.Tests/NLogTarget.Net45.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="NLog" Version="4.4.12" />
<ProjectReference Include="..\..\src\NLogTarget\NLogTarget.csproj" />
<Reference Include="System.Net.Http" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="NLog" Version="4.5.0" />
<ProjectReference Include="..\..\src\NLogTarget\NLogTarget.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="log4net" Version="2.0.5" />
<ProjectReference Include="..\..\src\TraceListener\TraceListener.csproj" />
<Reference Include="System.Net.Http" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="System.Diagnostics.TraceSource" Version="4.3.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion test/Xdt.Tests/Xdt.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.9.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0-beta4" />
<PackageReference Include="Microsoft.Web.Xdt" Version="2.1.1" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
Expand Down