Skip to content

Commit

Permalink
NLogTarget - Use FlushAsync instead of synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot committed Aug 13, 2024
1 parent e623c1b commit ea79e58
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 1 addition & 12 deletions LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit ea79e58

Please sign in to comment.