Skip to content

Commit b2b184f

Browse files
authored
Setup App insights (#3)
* added app insights * Update Startup.cs cleaned up app insights initialization
1 parent dee55f8 commit b2b184f

File tree

6 files changed

+30
-26
lines changed

6 files changed

+30
-26
lines changed
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.0</TargetFramework>
55
</PropertyGroup>
66

7-
87
<ItemGroup>
8+
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.8.0" />
9+
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.11.0" />
10+
<PackageReference Include="Microsoft.ApplicationInsights.Web" Version="2.11.0" />
11+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.9.6">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
<PackageReference Include="Microsoft.CodeAnalysis.Razor" Version="3.0.0" />
921
</ItemGroup>
1022

1123
</Project>

src/AspNetCoreShiftLeft.Web/Pages/Shared/_Layout.cshtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
<!DOCTYPE html>
1+
@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
2+
<!DOCTYPE html>
23
<html lang="en">
34
<head>
45
<meta charset="utf-8" />
56
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
67
<title>@ViewData["Title"] - AspNetCoreShiftLeft.Web</title>
78
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
89
<link rel="stylesheet" href="~/css/site.css" />
10+
@Html.Raw(JavaScriptSnippet.FullScript)
911
</head>
1012
<body>
1113
<header>

src/AspNetCoreShiftLeft.Web/Startup.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
52
using Microsoft.AspNetCore.Builder;
63
using Microsoft.AspNetCore.Hosting;
7-
using Microsoft.AspNetCore.HttpsPolicy;
84
using Microsoft.Extensions.Configuration;
95
using Microsoft.Extensions.DependencyInjection;
106
using Microsoft.Extensions.Hosting;
@@ -23,6 +19,7 @@ public Startup(IConfiguration configuration)
2319
// This method gets called by the runtime. Use this method to add services to the container.
2420
public void ConfigureServices(IServiceCollection services)
2521
{
22+
services.AddApplicationInsightsTelemetry(Configuration);
2623
services.AddRazorPages();
2724
}
2825

@@ -53,4 +50,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
5350
});
5451
}
5552
}
56-
}
53+
}

src/AspNetCoreShiftLeft.Web/appsettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"ApplicationInsights": {
3+
"InstrumentationKey": ""
4+
},
25
"Logging": {
36
"LogLevel": {
47
"Default": "Information",

test/AspNetCoreShiftLeft.Web.Tests/AspNetCoreShiftLeft.Web.Tests.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
11-
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
12-
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
13-
<PackageReference Include="coverlet.collector" Version="1.0.1" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
12+
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
13+
<PackageReference Include="coverlet.collector" Version="1.1.0">
14+
<PrivateAssets>all</PrivateAssets>
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
</PackageReference>
1417
</ItemGroup>
1518

1619
<ItemGroup>

test/AspNetCoreShiftLeft.Web.Tests/UnitTest1.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)