Skip to content

Commit a531e1f

Browse files
authored
Merge pull request #73175 from cijothomas/cithomas/small1
new FAQ about getting tc from DI for Ilogger.Java TOC fix
2 parents 53ddcef + 213d60e commit a531e1f

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

articles/azure-monitor/app/ilogger.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,16 +412,39 @@ The below code snippet configures logs `Warning` and above from all categories,
412412

413413
* Application Insights captures and sends `ILogger` logs using the same `TelemetryConfiguration` used for every other telemetry. There is an exception to this rule. The default `TelemetryConfiguration` is not fully set up when logging something from `Program.cs` or `Startup.cs` itself, so logs from these places will not have the default configuration, and hence will not be running all the `TelemetryInitializer`s and `TelemetryProcessor`s.
414414

415-
*5. What Application Insights telemetry type is produced from `ILogger` logs? or Where can I see `ILogger` logs in Application Insights?*
415+
*5. I'm using the standalone package Microsoft.Extensions.Logging.ApplicationInsights, and I want to log some additional custom telemetry manually. How should I do that?*
416+
417+
* When using the standalone package, `TelemetryClient` is not injected to DI container, so users are expected to create a new instance of `TelemetryClient` by using the same configuration as used by the logger provider, as shown below. This ensures the same configuration is used for all the custom telemetry, as well as those captured from ILogger.
418+
419+
```csharp
420+
public class MyController : ApiController
421+
{
422+
// This telemtryclient can be used to track additional telemetry using TrackXXX() api.
423+
private readonly TelemetryClient _telemetryClient;
424+
private readonly ILogger _logger;
425+
426+
public MyController(IOptions<TelemetryConfiguration> options, ILogger<MyController> logger)
427+
{
428+
_telemetryClient = new TelemetryClient(options.Value);
429+
_logger = logger;
430+
}
431+
}
432+
```
433+
434+
> [!NOTE]
435+
> Please note that, if the package Microsoft.ApplicationInsights.AspNetCore package is used to enable Application Insights, then the above example should be modified to get `TelemetryClient` directly in the constructor. See [this](https://docs.microsoft.com/azure/azure-monitor/app/asp-net-core-no-visualstudio#frequently-asked-questions) for full example.
436+
437+
438+
*6. What Application Insights telemetry type is produced from `ILogger` logs? or Where can I see `ILogger` logs in Application Insights?*
416439

417440
* ApplicationInsightsLoggerProvider captures `ILogger` logs and creates `TraceTelemetry` from it. If an Exception object is passed to the Log() method on ILogger, then instead of `TraceTelemetry`, an `ExceptionTelemetry` is created. These telemetry items can be found in same places as any other `TraceTelemetry` or `ExceptionTelemetry` for Application Insights, including portal, analytics, or Visual Studio local debugger.
418441
If you prefer to always send `TraceTelemetry`, then use the snippet ```builder.AddApplicationInsights((opt) => opt.TrackExceptionsAsExceptionTelemetry = false);```.
419442

420-
*5. I don't have SDK installed, and I use Azure Web App Extension to enable Application Insights for my Asp.Net Core applications. How do I use the new provider?*
443+
*7. I don't have SDK installed, and I use Azure Web App Extension to enable Application Insights for my Asp.Net Core applications. How do I use the new provider?*
421444

422445
* Application Insights extension in Azure Web App uses the old provider. Filtering rules can be modified in `appsettings.json` for your application. If you want to take advantage of the new provider, use build-time instrumentation by taking nuget dependency on the SDK. This document will be updated when extension switches to use the new provider.
423446

424-
*6. I am using the standalone package Microsoft.Extensions.Logging.ApplicationInsights, and enabling Application Insights provider by calling builder.AddApplicationInsights("ikey"). Is there an option to get instrumentation key from configuration?*
447+
*8. I am using the standalone package Microsoft.Extensions.Logging.ApplicationInsights, and enabling Application Insights provider by calling builder.AddApplicationInsights("ikey"). Is there an option to get instrumentation key from configuration?*
425448

426449

427450
* Modify `Program.cs` and `appsettings.json` as shown below.

articles/azure-monitor/toc.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,7 @@
347347
- name: Java apps
348348
items:
349349
- name: Web apps
350-
href: app/java-get-started.md
351-
- name: Web apps - runtime
352-
href: app/java-live.md
350+
href: app/java-get-started.md
353351
- name: Docker apps
354352
href: app/docker.md
355353
- name: Log traces

0 commit comments

Comments
 (0)