From d60fa51ed9bc744221de0068a06a41b27c0f52c2 Mon Sep 17 00:00:00 2001 From: Georg Jung Date: Tue, 19 May 2020 13:54:32 +0300 Subject: [PATCH] add application insights --- WoL/Startup.cs | 15 ++++++++++++++- WoL/WoL.csproj | 1 + WoL/appsettings.json | 6 +++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/WoL/Startup.cs b/WoL/Startup.cs index f54c24f..36345f9 100644 --- a/WoL/Startup.cs +++ b/WoL/Startup.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.ApplicationInsights.Channel; +using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Hosting; @@ -46,10 +48,22 @@ private void ConfigureDbContext(IServiceCollection services) } } + private void ConfigureAppInsights(IServiceCollection services) + { + var aiStorageFolder = Configuration.GetValue("ApplicationInsightsStorageFolder", null); + if (aiStorageFolder != null) + { + // For Linux OS + services.AddSingleton(new ServerTelemetryChannel { StorageFolder = aiStorageFolder }); + } + services.AddApplicationInsightsTelemetry(); + } + // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + ConfigureAppInsights(services); ConfigureDbContext(services); services.AddRazorPages(); services.AddServerSideBlazor(); @@ -61,7 +75,6 @@ public void ConfigureServices(IServiceCollection services) services.AddTransient(); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Argumente von öffentlichen Methoden validieren", Justification = "Called by the runtime, app will not be null")] public void Configure(IApplicationBuilder app, IWebHostEnvironment env) diff --git a/WoL/WoL.csproj b/WoL/WoL.csproj index 3cc491a..c490586 100644 --- a/WoL/WoL.csproj +++ b/WoL/WoL.csproj @@ -6,6 +6,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/WoL/appsettings.json b/WoL/appsettings.json index d59512b..d808c5b 100644 --- a/WoL/appsettings.json +++ b/WoL/appsettings.json @@ -13,5 +13,9 @@ }, "AllowedHosts": "*", "AutoUpdateDatabase": true, - "RequireHttps": false + "RequireHttps": false, + "ApplicationInsights": { + "InstrumentationKey": null + }, + "ApplicationInsightsStorageFolder": null }