From ea79e58102af5a3355a4f92e228d6e9877aadd8c Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Tue, 13 Aug 2024 21:46:49 +0200 Subject: [PATCH] NLogTarget - Use FlushAsync instead of synchronous --- CHANGELOG.md | 1 + LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs | 13 +------------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 049c0f363..5d2dd920f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## VNext - [Populate required field Message with "n/a" if it is empty](https://github.com/microsoft/ApplicationInsights-dotnet/issues/1066) +- [NLog Target with support for specifying ConnectionString](https://github.com/microsoft/ApplicationInsights-dotnet/issues/2897) ## Version 2.22.0 - no changes since beta. diff --git a/LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs b/LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs index de6a5a77a..d4ba9304a 100644 --- a/LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs +++ b/LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs @@ -187,18 +187,7 @@ protected override void FlushAsync(AsyncContinuation asyncContinuation) try { - this.TelemetryClient.Flush(); - if (DateTime.UtcNow.AddSeconds(-30) > this.lastLogEventTime) - { - // Nothing has been written, so nothing to wait for - asyncContinuation(null); - } - else - { - // Documentation says it is important to wait after flush, else nothing will happen - // https://docs.microsoft.com/azure/application-insights/app-insights-api-custom-events-metrics#flushing-data - System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(500)).ContinueWith((task) => asyncContinuation(null)); - } + this.TelemetryClient.FlushAsync(System.Threading.CancellationToken.None).ContinueWith(t => asyncContinuation(t.Exception)); } catch (Exception ex) {