Skip to content

Commit 51a7188

Browse files
authored
Update docs on ILogger for ASP.NET Core 3.0 change
ILogger can no longer be injected in to Startup.cs or Program.cs in ASP.NET Core apps, starting with version 3.0. See aspnet/Announcements#353 for the rationale behind this change. Updating the doc as there was some confusion from our customers when reading this doc (dotnet/extensions#1096).
1 parent 4a9059e commit 51a7188

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

articles/azure-monitor/app/ilogger.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public class ValuesController : ControllerBase
102102

103103
### Capture ILogger logs from Startup.cs and Program.cs in ASP.NET Core apps
104104

105+
> [!NOTE]
106+
> In ASP.NET Core 3.0 and later, it is no longer possible to inject `ILogger` in Startup.cs and Program.cs. See https://github.com/aspnet/Announcements/issues/353 for more details.
107+
105108
The new ApplicationInsightsLoggerProvider can capture logs from early in the application-startup pipeline. Although ApplicationInsightsLoggerProvider is automatically enabled in Application Insights (starting with version 2.7.0-beta3), it doesn't have an instrumentation key set up until later in the pipeline. So, only logs from **Controller**/other classes will be captured. To capture every log starting with **Program.cs** and **Startup.cs** itself, you must explicitly enable an instrumentation key for ApplicationInsightsLoggerProvider. Also, *TelemetryConfiguration* is not fully set up when you log from **Program.cs** or **Startup.cs** itself. So those logs will have a minimum configuration that uses InMemoryChannel, no sampling, and no standard telemetry initializers or processors.
106109

107110
The following examples demonstrate this capability with **Program.cs** and **Startup.cs**.

0 commit comments

Comments
 (0)