Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## VNext
- Update endpoint redirect header name for QuickPulse module to v2
- AzureSdkDiagnosticListener modified to use sdkversion prefix "rdddsaz" instead of "dotnet".
- [Log entries marked with LogLeve.None are now ignored by ApplicationInsightsLogger](https://github.com/microsoft/ApplicationInsights-dotnet/pull/2667). Fixes ([#2666](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2666))

## Version 2.21.0
- no changes since beta.
Expand Down
2 changes: 1 addition & 1 deletion LOGGING/src/ILogger/ApplicationInsightsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public IDisposable BeginScope<TState>(TState state)
/// </returns>
public bool IsEnabled(LogLevel logLevel)
{
return this.telemetryClient.IsEnabled();
return logLevel != LogLevel.None && this.telemetryClient.IsEnabled();
}

/// <summary>
Expand Down
32 changes: 32 additions & 0 deletions LOGGING/test/ILogger.Tests/ILoggerIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void ApplicationInsightsLoggerIsInvokedWhenUsingILogger()
testLogger.LogTrace("Trace");
testLogger.LogWarning("Warning");
testLogger.LogDebug("Debug");
testLogger.Log(LogLevel.None, "None");

Assert.AreEqual(7, itemsReceived.Count);

Expand Down Expand Up @@ -125,6 +126,37 @@ public void ApplicationInsightsLoggerIsInvokedWhenUsingILogger()
Assert.AreEqual("Debug", (itemsReceived[6] as TraceTelemetry).Message);
}

/// <summary>
/// Ensures that <see cref="ApplicationInsightsLogger"/> is invoked when user logs using <see cref="ILogger"/>.
/// </summary>
[TestMethod]
[TestCategory("ILogger")]
public void ApplicationInsightsLoggerIsNotInvokedWhenUsingILoggerAndTelemetryIsDisabled()
{
List<ITelemetry> itemsReceived = new List<ITelemetry>();

IServiceProvider serviceProvider = ILoggerIntegrationTests.SetupApplicationInsightsLoggerIntegration((telemetryItem, telemetryProcessor) =>
{
itemsReceived.Add(telemetryItem);
}, configuration =>
{
configuration.DisableTelemetry = true;
});

ILogger<ILoggerIntegrationTests> testLogger = serviceProvider.GetRequiredService<ILogger<ILoggerIntegrationTests>>();

testLogger.LogInformation("Testing");
testLogger.LogError(new Exception("ExceptionMessage"), "LoggerMessage");
testLogger.LogInformation(new EventId(100, "TestEvent"), "TestingEvent");
testLogger.LogCritical("Critical");
testLogger.LogTrace("Trace");
testLogger.LogWarning("Warning");
testLogger.LogDebug("Debug");
testLogger.Log(LogLevel.None, "None");

Assert.AreEqual(0, itemsReceived.Count);
}

/// <summary>
/// Ensures that the <see cref="ApplicationInsightsLoggerOptions.TrackExceptionsAsExceptionTelemetry"/> switch is honored
/// and exceptions are logged as trace messages when value is true.
Expand Down