mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-16 18:47:40 -05:00
Flush telemetry on shutdown
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using ChrisKaczor.HomeMonitor.Power.Service.Data;
|
using ChrisKaczor.HomeMonitor.Power.Service.Data;
|
||||||
|
using Microsoft.ApplicationInsights;
|
||||||
using Microsoft.ApplicationInsights.Extensibility;
|
using Microsoft.ApplicationInsights.Extensibility;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
@@ -7,6 +8,7 @@ using Microsoft.AspNetCore.ResponseCompression;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace ChrisKaczor.HomeMonitor.Power.Service
|
namespace ChrisKaczor.HomeMonitor.Power.Service
|
||||||
{
|
{
|
||||||
@@ -16,7 +18,8 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
|||||||
{
|
{
|
||||||
services.AddSingleton<ITelemetryInitializer, TelemetryInitializer>();
|
services.AddSingleton<ITelemetryInitializer, TelemetryInitializer>();
|
||||||
|
|
||||||
services.AddApplicationInsightsTelemetry(options => {
|
services.AddApplicationInsightsTelemetry(options =>
|
||||||
|
{
|
||||||
options.EnableDependencyTrackingTelemetryModule = false;
|
options.EnableDependencyTrackingTelemetryModule = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,12 +40,21 @@ namespace ChrisKaczor.HomeMonitor.Power.Service
|
|||||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
|
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder applicationBuilder, IWebHostEnvironment environment)
|
public void Configure(IApplicationBuilder applicationBuilder, IWebHostEnvironment environment, IHostApplicationLifetime hostApplicationLifetime)
|
||||||
{
|
{
|
||||||
if (environment.IsDevelopment())
|
if (environment.IsDevelopment())
|
||||||
applicationBuilder.UseDeveloperExceptionPage();
|
applicationBuilder.UseDeveloperExceptionPage();
|
||||||
|
|
||||||
var database = applicationBuilder.ApplicationServices.GetService<Database>();
|
hostApplicationLifetime.ApplicationStopping.Register(() =>
|
||||||
|
{
|
||||||
|
var telemetryClient = applicationBuilder.ApplicationServices.GetRequiredService<TelemetryClient>();
|
||||||
|
|
||||||
|
telemetryClient.Flush();
|
||||||
|
|
||||||
|
Thread.Sleep(5000);
|
||||||
|
});
|
||||||
|
|
||||||
|
var database = applicationBuilder.ApplicationServices.GetRequiredService<Database>();
|
||||||
database.EnsureDatabase();
|
database.EnsureDatabase();
|
||||||
|
|
||||||
applicationBuilder.UseCors("CorsPolicy");
|
applicationBuilder.UseCors("CorsPolicy");
|
||||||
|
|||||||
Reference in New Issue
Block a user