From b81d8eda52bbe850112d2de284dd51e249891014 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 --- .../src/NLogTarget/ApplicationInsightsTarget.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs b/LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs index de6a5a77a..dc7f0dc96 100644 --- a/LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs +++ b/LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs @@ -187,19 +187,8 @@ 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) { asyncContinuation(ex);