You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-monitor/app/ilogger.md
+18-17Lines changed: 18 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,14 +2,14 @@
2
2
title: Application Insights logging with .NET
3
3
description: Learn how to use Application Insights with the ILogger interface in .NET.
4
4
ms.topic: conceptual
5
-
ms.date: 01/24/2023
5
+
ms.date: 04/24/2023
6
6
ms.devlang: csharp
7
7
ms.reviewer: casocha
8
8
---
9
9
10
10
# Application Insights logging with .NET
11
11
12
-
In this article, you'll learn how to capture logs with Application Insights in .NET apps by using the [`Microsoft.Extensions.Logging.ApplicationInsights`][nuget-ai] provider package. If you use this provider, you can query and analyze your logs by using the Application Insights tools.
12
+
In this article, you learn how to capture logs with Application Insights in .NET apps by using the [`Microsoft.Extensions.Logging.ApplicationInsights`][nuget-ai] provider package. If you use this provider, you can query and analyze your logs by using the Application Insights tools.
With the NuGet package installed, and the provider being registered with dependency injection, the app is ready to log. With constructor injection, either <xref:Microsoft.Extensions.Logging.ILogger> or the generic-type alternative <xref:Microsoft.Extensions.Logging.ILogger%601> is required. When these implementations are resolved, `ApplicationInsightsLoggerProvider`will provide them. Logged messages or exceptions will be sent to Application Insights.
117
+
With the NuGet package installed, and the provider being registered with dependency injection, the app is ready to log. With constructor injection, either <xref:Microsoft.Extensions.Logging.ILogger> or the generic-type alternative <xref:Microsoft.Extensions.Logging.ILogger%601> is required. When these implementations are resolved, `ApplicationInsightsLoggerProvider`provides them. Logged messages or exceptions are sent to Application Insights.
118
118
119
119
Consider the following example controller:
120
120
@@ -139,7 +139,7 @@ public class ValuesController : ControllerBase
139
139
}
140
140
```
141
141
142
-
For more information, see [Logging in ASP.NET Core](/aspnet/core/fundamentals/logging).
142
+
For more information, see [Logging in ASP.NET Core](/aspnet/core/fundamentals/logging) and [What Application Insights telemetry type is produced from ILogger logs? Where can I see ILogger logs in Application Insights?](#what-application-insights-telemetry-type-is-produced-from-ilogger-logs-where-can-i-see-ilogger-logs-in-application-insights).
143
143
144
144
## Console application
145
145
@@ -241,8 +241,22 @@ namespace ConsoleApp
241
241
242
242
---
243
243
244
+
For more information, see [What Application Insights telemetry type is produced from ILogger logs? Where can I see ILogger logs in Application Insights?](#what-application-insights-telemetry-type-is-produced-from-ilogger-logs-where-can-i-see-ilogger-logs-in-application-insights).
245
+
244
246
## Frequently asked questions
245
247
248
+
### What Application Insights telemetry type is produced from ILogger logs? Where can I see ILogger logs in Application Insights?
249
+
250
+
`ApplicationInsightsLoggerProvider` captures `ILogger` logs and creates `TraceTelemetry` from them. If an `Exception` object is passed to the `Log` method on `ILogger`, `ExceptionTelemetry` is created instead of `TraceTelemetry`.
251
+
252
+
These telemetry items can be found in the same places as any other `TraceTelemetry` or `ExceptionTelemetry` items for Application Insights, including the Azure portal, analytics, or the Visual Studio local debugger.
253
+
254
+
If you prefer to always send `TraceTelemetry`, use this snippet:
### Why do some ILogger logs not have the same properties as others?
247
261
248
262
Application Insights captures and sends `ILogger` logs by using the same `TelemetryConfiguration` information that's used for every other telemetry. But there's an exception. By default, `TelemetryConfiguration` isn't fully set up when you log from *Program.cs* or *Startup.cs*. Logs from these places won't have the default configuration, so they won't be running all `TelemetryInitializer` instances and `TelemetryProcessor` instances.
@@ -269,19 +283,6 @@ public class MyController : ApiController
269
283
> [!NOTE]
270
284
> If you use the `Microsoft.ApplicationInsights.AspNetCore` package to enable Application Insights, modify this code to get `TelemetryClient` directly in the constructor. For an example, see [this FAQ](../faq.yml).
271
285
272
-
### What Application Insights telemetry type is produced from ILogger logs? Where can I see ILogger logs in Application Insights?
273
-
274
-
`ApplicationInsightsLoggerProvider` captures `ILogger` logs and creates `TraceTelemetry` from them. If an `Exception` object is passed to the `Log` method on `ILogger`, `ExceptionTelemetry` is created instead of `TraceTelemetry`.
275
-
276
-
These telemetry items can be found in the same places as any other `TraceTelemetry` or `ExceptionTelemetry` items for Application Insights, including the Azure portal, analytics, or the Visual Studio local debugger.
277
-
278
-
If you prefer to always send `TraceTelemetry`, use this snippet:
### I don't have the SDK installed, and I use the Azure Web Apps extension to enable Application Insights for my ASP.NET Core applications. How do I use the new provider?
286
287
287
288
The Application Insights extension in Azure Web Apps uses the new provider. You can modify the filtering rules in the *appsettings.json* file for your application.
0 commit comments