public static IApplicationBuilder UseHttpReports(this IApplicationBuilder app) { ServiceContainer.Provider = app.ApplicationServices.GetRequiredService <IServiceProvider>() ?? throw new ArgumentNullException("ServiceProvider Init Failed"); Activity.DefaultIdFormat = ActivityIdFormat.W3C; var backgroundService = app.ApplicationServices.GetRequiredService <IBackgroundService>(); backgroundService.StartAsync(app); var options = app.ApplicationServices.GetRequiredService <IOptions <HttpReportsOptions> >(); if (!options.Value.Switch) { return(null); } app.Map(BasicConfig.HttpReportsDefaultHealth, builder => { builder.Run(async context => await context.Response.WriteAsync(DateTime.Now.ToShortTimeString()) ); }); app.UseMiddleware <DefaultHttpReportsMiddleware>(); TraceDiagnsticListenerObserver observer = app.ApplicationServices.GetRequiredService <TraceDiagnsticListenerObserver>(); DiagnosticListener.AllListeners.Subscribe(observer); return(app); }
public static IApplicationBuilder UseHttpReports(this IApplicationBuilder app) { ServiceContainer.Provider = app.ApplicationServices.GetRequiredService <IServiceProvider>() ?? throw new ArgumentNullException("ServiceProvider Init Failed"); Activity.DefaultIdFormat = ActivityIdFormat.W3C; app.ApplicationServices.GetService <IHttpReportsStorage>()?.InitAsync().Wait(); var backgroundService = app.ApplicationServices.GetRequiredService <IBackgroundService>(); backgroundService.StartAsync(app); var options = app.ApplicationServices.GetRequiredService <IOptions <HttpReportsOptions> >(); if (!options.Value.Switch) { return(null); } app.UseMiddleware <DefaultHttpReportsMiddleware>(); TraceDiagnsticListenerObserver observer = app.ApplicationServices.GetRequiredService <TraceDiagnsticListenerObserver>(); System.Diagnostics.DiagnosticListener.AllListeners.Subscribe(observer); return(app); }