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 2 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
8 changes: 4 additions & 4 deletions GlobalStaticVersion.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
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.
-->
<SemanticVersionDate>2018-12-31</SemanticVersionDate>
<SemanticVersionDate>2018-04-26</SemanticVersionDate>

<PreReleaseVersionFileName>.PreReleaseVersion</PreReleaseVersionFileName>
<PreReleaseVersionFilePath>$(MSBuildThisFileDirectory)$(PreReleaseVersionFileName)</PreReleaseVersionFilePath>
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
7 changes: 6 additions & 1 deletion src/ILogger/ApplicationInsightsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ 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),
};

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 @@ -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 @@ -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["{OriginalFormat}"]);
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["{OriginalFormat}"]);
}

/// <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