forked from gzepeda/ApplicationInsights-aspnetcore
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added explicit setting of the SDK version to ILogger trace calls. (mi…
…crosoft#322) * Added explicit setting of the SDK version to ILogger trace calls. * Switched to explicit types for readability. * Added unit test for AI ILogger setting SDK version on telemetry context.
- Loading branch information
Showing
2 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../Microsoft.ApplicationInsights.AspNetCore.Tests/Logging/ApplicationInsightsLoggerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Microsoft.ApplicationInsights.AspNetCore.Logging; | ||
using Microsoft.ApplicationInsights.AspNetCore.Tests.Helpers; | ||
using Microsoft.ApplicationInsights.Extensibility.Implementation; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit; | ||
|
||
namespace Microsoft.ApplicationInsights.AspNetCore.Tests.Logging | ||
{ | ||
/// <summary> | ||
/// Tests for the Application Insights ILogger implementation. | ||
/// </summary> | ||
public class ApplicationInsightsLoggerTests | ||
{ | ||
/// <summary> | ||
/// Tests that the SDK version is correctly set on the telemetry context when messages are logged to AI. | ||
/// </summary> | ||
[Fact] | ||
public void TestLoggerSetsSdkVersionOnLoggedTelemetry() | ||
{ | ||
bool isCorrectVersion = false; | ||
TelemetryClient client = CommonMocks.MockTelemetryClient((t) => | ||
{ | ||
isCorrectVersion = t.Context.GetInternalContext().SdkVersion.StartsWith(SdkVersionUtils.VersionPrefix); | ||
}); | ||
|
||
ILogger logger = new ApplicationInsightsLogger("test", client, (s, l) => { return true; }); | ||
logger.LogTrace("This is a test.", new object[] { }); | ||
Assert.True(isCorrectVersion); | ||
} | ||
} | ||
} |