Skip to content

Commit ef6eb48

Browse files
Merge pull request #235561 from AaronMaxwell/aaronmax-ilogger-where-is-telemetry
where to find ilogger telemetry more prominent
2 parents 1fa8594 + a2f44f1 commit ef6eb48

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

articles/azure-monitor/app/ilogger.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
title: Application Insights logging with .NET
33
description: Learn how to use Application Insights with the ILogger interface in .NET.
44
ms.topic: conceptual
5-
ms.date: 01/24/2023
5+
ms.date: 04/24/2023
66
ms.devlang: csharp
77
ms.reviewer: casocha
88
---
99

1010
# Application Insights logging with .NET
1111

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.
1313

1414
[nuget-ai]: https://www.nuget.org/packages/Microsoft.Extensions.Logging.ApplicationInsights
1515
[nuget-ai-ws]: https://www.nuget.org/packages/Microsoft.ApplicationInsights.WorkerService
@@ -114,7 +114,7 @@ namespace WebApplication
114114

115115
---
116116

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` 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.
118118

119119
Consider the following example controller:
120120

@@ -139,7 +139,7 @@ public class ValuesController : ControllerBase
139139
}
140140
```
141141

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).
143143

144144
## Console application
145145

@@ -241,8 +241,22 @@ namespace ConsoleApp
241241

242242
---
243243

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+
244246
## Frequently asked questions
245247

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:
255+
256+
```csharp
257+
builder.AddApplicationInsights(
258+
options => options.TrackExceptionsAsExceptionTelemetry = false);
259+
```
246260
### Why do some ILogger logs not have the same properties as others?
247261

248262
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
269283
> [!NOTE]
270284
> 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).
271285
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:
279-
280-
```csharp
281-
builder.AddApplicationInsights(
282-
options => options.TrackExceptionsAsExceptionTelemetry = false);
283-
```
284-
285286
### 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?
286287

287288
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

Comments
 (0)