Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,10 @@ public void TrackTraceWithTraceTelemetryAndProperties()
[Fact]
public void TrackTraceWithTraceTelemetryAndAllSeverityLevels()
{
// Test all severity levels in sequence (Note: Verbose/Trace may be filtered by default logger configuration)
// Test all severity levels
var testData = new[]
{
(SeverityLevel.Verbose, LogLevel.Debug, "Trace-Verbose"),
(SeverityLevel.Information, LogLevel.Information, "Trace-Information"),
(SeverityLevel.Warning, LogLevel.Warning, "Trace-Warning"),
(SeverityLevel.Error, LogLevel.Error, "Trace-Error"),
Expand All @@ -537,7 +538,7 @@ public void TrackTraceWithTraceTelemetryAndAllSeverityLevels()
this.telemetryClient.Flush();

// Verify all logs were collected
Assert.True(this.logItems.Count >= 4, $"Expected at least 4 logs, but got {this.logItems.Count}");
Assert.True(this.logItems.Count >= 5, $"Expected at least 5 logs, but got {this.logItems.Count}");

// Verify each severity level was logged correctly
foreach (var (severity, expectedLogLevel, message) in testData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Microsoft.ApplicationInsights
using Azure.Monitor.OpenTelemetry.Exporter;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Internal;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
using OpenTelemetry.Resources;

Expand All @@ -34,8 +36,19 @@ public static IOpenTelemetryBuilder WithApplicationInsights(this IOpenTelemetryB
.WithMetrics(metrics => metrics.AddMeter(TelemetryConfiguration.ApplicationInsightsMeterName))
.WithTracing(tracing => tracing.AddSource(TelemetryConfiguration.ApplicationInsightsActivitySourceName));

// Note: Connection string should be set via UseAzureMonitor()
// when TelemetryConfiguration.ConnectionString is provided
// Ensure that all log severity levels (including Verbose/Debug) pass through
// the internal LoggerFactory for the TelemetryClient category. Without this,
// the default MinLevel of Information silently drops TrackTrace calls with
// SeverityLevel.Verbose. We target only the TelemetryClient category to avoid
// lowering the minimum level globally for other loggers in the pipeline.
builder.Services.Configure<LoggerFilterOptions>(options =>
{
options.Rules.Add(new LoggerFilterRule(
providerName: null,
categoryName: "Microsoft.ApplicationInsights.TelemetryClient",
logLevel: LogLevel.Trace,
filter: null));
});

return builder;
}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Changelog

## Unreleased
<<<<<<< harskaur/nlogMinLevel
- [Fix bug where Debug/Trace level logs from TrackTrace API were not emitted to Application Insights](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3121/changes)
=======
- [Fix Track API calls to not mutate the passed in dictionary if it is readonly](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3119)
>>>>>>> main

## Version 3.0.0
- [Replaced `netstandard2.0` with `net8.0` target framework in `Microsoft.ApplicationInsights.NLogTarget` package.](https://github.com/microsoft/ApplicationInsights-dotnet/pull/3102)
Expand Down
1 change: 0 additions & 1 deletion LOGGING/test/NLogTarget.Tests/TelemetryTestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public TelemetryConfiguration CreateConfiguration(string connectionString)
options.Transport = transport;
options.DisableOfflineStorage = true;
});
builder.Services.Configure<LoggerFilterOptions>(options => options.MinLevel = LogLevel.Trace);
builder.WithLogging(logging =>
logging.AddProcessor(new SimpleLogRecordExportProcessor(
new AzureMonitorRecordingLogExporter(this.collector, () => this.instrumentationKey))));
Expand Down
1 change: 1 addition & 0 deletions examples/BasicConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static void Main(string[] args)
telemetryClient.TrackEvent(new EventTelemetry("SampleEventObject"));
telemetryClient.TrackTrace("A trace message");
telemetryClient.TrackTrace("A warning", SeverityLevel.Warning);
telemetryClient.TrackTrace("A debug trace", SeverityLevel.Verbose);
telemetryClient.TrackTrace("A trace with properties", new System.Collections.Generic.Dictionary<string, string> { { "Key", "Value" } });
telemetryClient.TrackTrace("A trace with severity and properties", SeverityLevel.Error, new System.Collections.Generic.Dictionary<string, string> { { "Key", "Value" } });
telemetryClient.TrackTrace(new TraceTelemetry("TraceTelemetry object", SeverityLevel.Information));
Expand Down
2 changes: 1 addition & 1 deletion examples/NLogConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Console.WriteLine("================================================\n");

NLog.Common.InternalLogger.LogToConsole = true;
NLog.Common.InternalLogger.LogLevel = NLog.LogLevel.Warn;
NLog.Common.InternalLogger.LogLevel = NLog.LogLevel.Trace;

/*
// Optional: Configure Azure Active Directory (AAD) authentication
Expand Down
2 changes: 1 addition & 1 deletion examples/NLogConsoleApp/nlog.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

<rules>
<logger name="*" minlevel="Trace" writeTo="console" />
<logger name="*" minlevel="Info" writeTo="aiTarget" />
<logger name="*" minlevel="Trace" writeTo="aiTarget" />
</rules>
</nlog>
Loading