@@ -151,7 +151,9 @@ namespace WebApplication
151
151
// or when you need to capture logs during application startup, such as
152
152
// in Program.cs or Startup.cs itself.
153
153
builder .AddApplicationInsights (
154
- context .Configuration [" APPINSIGHTS_INSTRUMENTATIONKEY" ]);
154
+ configureTelemetryConfiguration : (config ) => config .ConnectionString = context .Configuration [" APPLICATIONINSIGHTS_CONNECTION_STRING" ],
155
+ configureApplicationInsightsLoggerOptions : (options ) => { }
156
+ );
155
157
156
158
// Capture all log-level entries from Program
157
159
builder .AddFilter <ApplicationInsightsLoggerProvider >(
@@ -165,9 +167,6 @@ namespace WebApplication
165
167
}
166
168
```
167
169
168
- In the preceding code, ` ApplicationInsightsLoggerProvider ` is configured with your ` "APPINSIGHTS_INSTRUMENTATIONKEY" ` instrumentation key. Filters are applied, setting the log level to < xref:Microsoft.Extensions.Logging.LogLevel.Trace?displayProperty=nameWithType > .
169
-
170
-
171
170
[ !INCLUDE [ azure-monitor-log-analytics-rebrand] ( ../../../includes/azure-monitor-instrumentation-key-deprecation.md )]
172
171
173
172
#### Example Startup.cs
@@ -260,7 +259,10 @@ namespace ConsoleApp
260
259
services .AddLogging (builder =>
261
260
{
262
261
// Only Application Insights is registered as a logger provider
263
- builder .AddApplicationInsights (" <YourInstrumentationKey>" );
262
+ builder .AddApplicationInsights (
263
+ configureTelemetryConfiguration : (config ) => config .ConnectionString = " <YourConnectionString>" ,
264
+ configureApplicationInsightsLoggerOptions : (options ) => { }
265
+ );
264
266
});
265
267
266
268
IServiceProvider serviceProvider = services .BuildServiceProvider ();
@@ -327,7 +329,10 @@ namespace ConsoleApp
327
329
services .AddLogging (builder =>
328
330
{
329
331
// Only Application Insights is registered as a logger provider
330
- builder .AddApplicationInsights (" <YourInstrumentationKey>" );
332
+ builder .AddApplicationInsights (
333
+ configureTelemetryConfiguration : (config ) => config .ConnectionString = " <YourConnectionString>" ,
334
+ configureApplicationInsightsLoggerOptions : (options ) => { }
335
+ );
331
336
});
332
337
333
338
IServiceProvider serviceProvider = services .BuildServiceProvider ();
0 commit comments