Skip to content

Commit aeca28a

Browse files
committed
fixed tabs
1 parent 7233a61 commit aeca28a

File tree

1 file changed

+82
-16
lines changed

1 file changed

+82
-16
lines changed

articles/azure-monitor/app/live-stream.md

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,65 @@ while (true)
109109
}
110110
```
111111

112+
# [.NET 5.0](#tab/dotnet5)
113+
114+
```csharp
115+
using Microsoft.ApplicationInsights;
116+
using Microsoft.ApplicationInsights.Extensibility;
117+
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse;
118+
using System;
119+
using System.Threading.Tasks;
120+
121+
namespace LiveStream50
122+
{
123+
internal class Program
124+
{
125+
static void Main(string[] args)
126+
{
127+
// Create a TelemetryConfiguration instance.
128+
TelemetryConfiguration config = TelemetryConfiguration.CreateDefault();
129+
config.InstrumentationKey = "INSTRUMENTATION-KEY-HERE";
130+
QuickPulseTelemetryProcessor quickPulseProcessor = null;
131+
config.DefaultTelemetrySink.TelemetryProcessorChainBuilder
132+
.Use((next) =>
133+
{
134+
quickPulseProcessor = new QuickPulseTelemetryProcessor(next);
135+
return quickPulseProcessor;
136+
})
137+
.Build();
138+
139+
var quickPulseModule = new QuickPulseTelemetryModule();
140+
141+
// Secure the control channel.
142+
// This is optional, but recommended.
143+
quickPulseModule.AuthenticationApiKey = "YOUR-API-KEY-HERE";
144+
quickPulseModule.Initialize(config);
145+
quickPulseModule.RegisterTelemetryProcessor(quickPulseProcessor);
146+
147+
// Create a TelemetryClient instance. It is important
148+
// to use the same TelemetryConfiguration here as the one
149+
// used to set up Live Metrics.
150+
TelemetryClient client = new TelemetryClient(config);
151+
152+
// This sample runs indefinitely. Replace with actual application logic.
153+
while (true)
154+
{
155+
// Send dependency and request telemetry.
156+
// These will be shown in Live Metrics.
157+
// CPU/Memory Performance counter is also shown
158+
// automatically without any additional steps.
159+
client.TrackDependency("My dependency", "target", "http://sample",
160+
DateTimeOffset.Now, TimeSpan.FromMilliseconds(300), true);
161+
client.TrackRequest("My Request", DateTimeOffset.Now,
162+
TimeSpan.FromMilliseconds(230), "200", true);
163+
Task.Delay(1000).Wait();
164+
}
165+
}
166+
}
167+
}
168+
169+
```
170+
112171
# [.NET Framework](#tab/dotnet-framework)
113172

114173
```csharp
@@ -251,21 +310,9 @@ It's possible to try custom filters without having to set up an authenticated ch
251310

252311
You can add an API key to configuration for ASP.NET, ASP.NET Core, WorkerService, and Azure Functions apps.
253312

254-
#### ASP.NET
255-
256-
In the *applicationinsights.config* file, add `AuthenticationApiKey` to `QuickPulseTelemetryModule`:
257-
258-
```xml
259-
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector">
260-
<AuthenticationApiKey>YOUR-API-KEY-HERE</AuthenticationApiKey>
261-
</Add>
262-
```
263-
264-
#### ASP.NET Core
265-
266-
For [ASP.NET Core](./asp-net-core.md) applications, follow these instructions.
313+
# [.NET 6.0+](#tab/dotnet6)
267314

268-
Modify `ConfigureServices` of your *Startup.cs* file as shown.
315+
Modify `ConfigureServices` of your *Program.cs* file as shown.
269316

270317
Add the following namespace:
271318

@@ -275,15 +322,23 @@ using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPuls
275322

276323
Then modify the `ConfigureServices` method:
277324

278-
# [.NET 6.0+](#tab/dotnet6)
279-
280325
```csharp
281326
// Existing code which includes services.AddApplicationInsightsTelemetry() to enable Application Insights.
282327
builder.Services.ConfigureTelemetryModule<QuickPulseTelemetryModule> ((module, o) => module.AuthenticationApiKey = "YOUR-API-KEY-HERE");
283328
```
284329

285330
# [.NET 5.0](#tab/dotnet5)
286331

332+
Modify `ConfigureServices` of your *Startup.cs* file as shown.
333+
334+
Add the following namespace:
335+
336+
```csharp
337+
using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse;
338+
```
339+
340+
Then modify the `ConfigureServices` method:
341+
287342
```csharp
288343
public void ConfigureServices(IServiceCollection services)
289344
{
@@ -292,6 +347,17 @@ public void ConfigureServices(IServiceCollection services)
292347
}
293348
```
294349

350+
# [.NET 5.0](#tab/dotnet-framework)
351+
352+
In the *applicationinsights.config* file, add `AuthenticationApiKey` to `QuickPulseTelemetryModule`:
353+
354+
```xml
355+
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector">
356+
<AuthenticationApiKey>YOUR-API-KEY-HERE</AuthenticationApiKey>
357+
</Add>
358+
```
359+
360+
295361
---
296362

297363
For more information on how to configure ASP.NET Core applications, see [Configuring telemetry modules in ASP.NET Core](./asp-net-core.md#configure-or-remove-default-telemetrymodules).

0 commit comments

Comments
 (0)