@@ -109,6 +109,65 @@ while (true)
109
109
}
110
110
```
111
111
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
+
112
171
# [ .NET Framework] ( #tab/dotnet-framework )
113
172
114
173
``` csharp
@@ -251,21 +310,9 @@ It's possible to try custom filters without having to set up an authenticated ch
251
310
252
311
You can add an API key to configuration for ASP.NET, ASP.NET Core, WorkerService, and Azure Functions apps.
253
312
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 )
267
314
268
- Modify ` ConfigureServices ` of your * Startup .cs* file as shown.
315
+ Modify ` ConfigureServices ` of your * Program .cs* file as shown.
269
316
270
317
Add the following namespace:
271
318
@@ -275,15 +322,23 @@ using Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPuls
275
322
276
323
Then modify the ` ConfigureServices ` method:
277
324
278
- # [ .NET 6.0+] ( #tab/dotnet6 )
279
-
280
325
``` csharp
281
326
// Existing code which includes services.AddApplicationInsightsTelemetry() to enable Application Insights.
282
327
builder .Services .ConfigureTelemetryModule <QuickPulseTelemetryModule > ((module , o ) => module .AuthenticationApiKey = " YOUR-API-KEY-HERE" );
283
328
```
284
329
285
330
# [ .NET 5.0] ( #tab/dotnet5 )
286
331
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
+
287
342
``` csharp
288
343
public void ConfigureServices (IServiceCollection services )
289
344
{
@@ -292,6 +347,17 @@ public void ConfigureServices(IServiceCollection services)
292
347
}
293
348
```
294
349
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
+
295
361
---
296
362
297
363
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