Skip to content

Commit 4afc52f

Browse files
Updates logging for Application Insights.
Ensures the initial logger is used when warning about a missing Application Insights connection string. This provides a more accurate representation of the application's startup phase.
1 parent c36dba0 commit 4afc52f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

EssentialCSharp.Web/Program.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private static void Main(string[] args)
4343
// Create a temporary logger for startup logging
4444
using var loggerFactory = LoggerFactory.Create(loggingBuilder =>
4545
loggingBuilder.AddConsole().SetMinimumLevel(LogLevel.Information));
46-
var logger = loggerFactory.CreateLogger<Program>();
46+
var initialLogger = loggerFactory.CreateLogger<Program>();
4747

4848
if (!builder.Environment.IsDevelopment())
4949
{
@@ -53,17 +53,17 @@ private static void Main(string[] args)
5353

5454
if (!string.IsNullOrEmpty(appInsightsConnectionString))
5555
{
56-
builder.Services.AddOpenTelemetry().UseAzureMonitor(
57-
options =>
58-
{
59-
options.ConnectionString = appInsightsConnectionString;
60-
});
56+
builder.Services.AddOpenTelemetry().UseAzureMonitor(
57+
options =>
58+
{
59+
options.ConnectionString = appInsightsConnectionString;
60+
});
6161
builder.Services.AddApplicationInsightsTelemetry();
6262
builder.Services.AddServiceProfiler();
6363
}
6464
else
6565
{
66-
logger.LogWarning("Application Insights connection string not found. Telemetry collection will be disabled.");
66+
initialLogger.LogWarning("Application Insights connection string not found. Telemetry collection will be disabled.");
6767
}
6868
}
6969

0 commit comments

Comments
 (0)