Skip to content

Commit

Permalink
add application insights
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-jung committed May 19, 2020
1 parent 3d7efd1 commit d60fa51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
15 changes: 14 additions & 1 deletion WoL/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,10 +48,22 @@ private void ConfigureDbContext(IServiceCollection services)
}
}

private void ConfigureAppInsights(IServiceCollection services)
{
var aiStorageFolder = Configuration.GetValue<string>("ApplicationInsightsStorageFolder", null);
if (aiStorageFolder != null)
{
// For Linux OS
services.AddSingleton<ITelemetryChannel>(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();
Expand All @@ -61,7 +75,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddTransient<IAddressLookupService, AddressLookupService>();
}


// 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)
Expand Down
1 change: 1 addition & 0 deletions WoL/WoL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="ArpLookup" Version="1.1.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.14.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
6 changes: 5 additions & 1 deletion WoL/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
},
"AllowedHosts": "*",
"AutoUpdateDatabase": true,
"RequireHttps": false
"RequireHttps": false,
"ApplicationInsights": {
"InstrumentationKey": null
},
"ApplicationInsightsStorageFolder": null
}

0 comments on commit d60fa51

Please sign in to comment.