Skip to content

Commit e11b481

Browse files
committed
fix(aspnetcore): skip shutdown hook when ExceptionlessLifetimeService is registered
UseExceptionless() now checks if ExceptionlessLifetimeService is already registered via AddExceptionless() hosting integration and skips the redundant ApplicationStopping callback to avoid double queue flushing.
1 parent 857342f commit e11b481

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/Platforms/Exceptionless.AspNetCore/ExceptionlessExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app,
4949
new ExceptionlessDiagnosticListener(client),
5050
eventName => ExceptionlessDiagnosticListener.IsRelevantEvent(eventName));
5151

52-
var lifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
53-
lifetime.ApplicationStopping.Register(() => client.ProcessQueueAsync().ConfigureAwait(false).GetAwaiter().GetResult());
52+
if (app.ApplicationServices.GetService<Exceptionless.Extensions.Hosting.ExceptionlessLifetimeService>() == null) {
53+
var lifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>();
54+
lifetime.ApplicationStopping.Register(() => client.ProcessQueueAsync().ConfigureAwait(false).GetAwaiter().GetResult());
55+
}
5456

5557
return app.UseMiddleware<ExceptionlessMiddleware>(client);
5658
}

0 commit comments

Comments
 (0)