Skip to content

Commit a40321f

Browse files
Merge pull request #218865 from kainawroth/patch-2
Adding .NET 6 version of enabling AI and Profiler
2 parents b0525e3 + 93437f6 commit a40321f

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

articles/azure-monitor/profiler/profiler-containers.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ In this article, you'll learn the various ways you can:
4747

4848
We've added delay in the `Controllers/WeatherForecastController.cs` project to simulate the bottleneck.
4949
50-
```CSharp
50+
```csharp
5151
[HttpGet(Name = "GetWeatherForecast")]
5252
public IEnumerable<WeatherForecast> Get()
5353
{
@@ -68,16 +68,36 @@ In this article, you'll learn the various ways you can:
6868
dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore
6969
```
7070
71-
1. Enable Application Insights and Profiler in `Startup.cs`:
71+
1. Enable Application Insights and Profiler:
72+
73+
### [ASP.NET Core 6 and later](#tab/net-core-new)
74+
75+
Add `builder.Services.AddApplicationInsightsTelemetry()` and `builder.Services.AddServiceProfiler()` after the `WebApplication.CreateBuilder()` method in `Program.cs`:
76+
77+
```csharp
78+
var builder = WebApplication.CreateBuilder(args);
7279
73-
```csharp
74-
public void ConfigureServices(IServiceCollection services)
75-
{
76-
services.AddApplicationInsightsTelemetry(); // Add this line of code to enable Application Insights.
77-
services.AddServiceProfiler(); // Add this line of code to Enable Profiler
78-
services.AddControllersWithViews();
79-
}
80-
```
80+
builder.Services.AddApplicationInsightsTelemetry(); // Add this line of code to enable Application Insights.
81+
builder.Services.AddServiceProfiler(); // Add this line of code to enable Profiler
82+
builder.Services.AddControllersWithViews();
83+
84+
var app = builder.Build();
85+
```
86+
87+
### [ASP.NET Core 5 and earlier](#tab/net-core-old)
88+
89+
Add `services.AddApplicationInsightsTelemetry()` and `services.AddServiceProfiler()` to the `ConfigureServices()` method in `Startup.cs`:
90+
91+
```csharp
92+
public void ConfigureServices(IServiceCollection services)
93+
{
94+
services.AddApplicationInsightsTelemetry(); // Add this line of code to enable Application Insights.
95+
services.AddServiceProfiler(); // Add this line of code to enable Profiler
96+
services.AddControllersWithViews();
97+
}
98+
```
99+
100+
---
81101
82102
## Pull the latest ASP.NET Core build/runtime images
83103

0 commit comments

Comments
 (0)