Skip to content

Commit 958f8eb

Browse files
committed
[AppInsights][AaronMax] updating code samples for connection strings
1 parent 6b4ba50 commit 958f8eb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

articles/azure-monitor/app/ilogger.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ namespace WebApplication
151151
// or when you need to capture logs during application startup, such as
152152
// in Program.cs or Startup.cs itself.
153153
builder.AddApplicationInsights(
154-
context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]);
154+
configureTelemetryConfiguration: (config) => config.ConnectionString = context.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"],
155+
configureApplicationInsightsLoggerOptions: (options) => { }
156+
);
155157

156158
// Capture all log-level entries from Program
157159
builder.AddFilter<ApplicationInsightsLoggerProvider>(
@@ -165,9 +167,6 @@ namespace WebApplication
165167
}
166168
```
167169

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-
171170
[!INCLUDE [azure-monitor-log-analytics-rebrand](../../../includes/azure-monitor-instrumentation-key-deprecation.md)]
172171

173172
#### Example Startup.cs
@@ -260,7 +259,10 @@ namespace ConsoleApp
260259
services.AddLogging(builder =>
261260
{
262261
// 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+
);
264266
});
265267

266268
IServiceProvider serviceProvider = services.BuildServiceProvider();
@@ -327,7 +329,10 @@ namespace ConsoleApp
327329
services.AddLogging(builder =>
328330
{
329331
// 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+
);
331336
});
332337

333338
IServiceProvider serviceProvider = services.BuildServiceProvider();

0 commit comments

Comments
 (0)