Send diagnostic tracing logs for your ASP.NET/ASP.NET Core application from ILogger, NLog, log4Net, or System.Diagnostics.Trace to Azure Application Insights. For Python applications, send diagnostic tracing logs by using AzureLogHandler in OpenCensus Python for Azure Monitor. You can then explore and search for them. Those logs are merged with the other log files from your application. You can use them to identify traces that are associated with each user request and correlate them with other events and exception reports.
Do you need the log-capture module? It's a useful adapter for third-party loggers. But if you aren't already using NLog, log4Net, or System.Diagnostics.Trace, consider calling Application Insights TrackTrace() directly.
On March 31, 2025, support for instrumentation key ingestion will end. Instrumentation key ingestion will continue to work, but we'll no longer provide updates or support for the feature. Transition to connection strings to take advantage of new capabilities.
Install your chosen logging framework in your project, which should result in an entry in app.config or web.config.
Add Application Insights to your project if you haven't done that yet and there is an option to include the log collector.
Or right-click your project in Solution Explorer to Configure Application Insights. Select the Configure trace collection option.
No Application Insights menu or log collector option? Try Troubleshooting.
Use this method if your project type isn't supported by the Application Insights installer. For example, if it's a Windows desktop project.
The NuGet package installs the necessary assemblies and modifies web.config or app.config if that's applicable.
For examples of using the Application Insights ILogger implementation with console applications and ASP.NET Core, see ApplicationInsightsLoggerProvider for .NET Core ILogger logs.
If you use System.Diagnostics.Trace, a typical call would be:
System.Diagnostics.Trace.TraceWarning("Slow response - database01");
If you prefer log4net or NLog, use:
logger.Warn("Slow response - database01");
You can configure System.Diagnostics.Tracing.EventSource events to be sent to Application Insights as traces. First, install the Microsoft.ApplicationInsights.EventSourceListener NuGet package. Then edit the TelemetryModules section of the ApplicationInsights.config file.
For each source, you can set the following parameters:
You can configure System.Diagnostics.DiagnosticSource events to be sent to Application Insights as traces. First, install the Microsoft.ApplicationInsights.DiagnosticSourceListener NuGet package. Then edit the "TelemetryModules" section of the ApplicationInsights.config file.
For each diagnostic source you want to trace, add an entry with the Name attribute set to the name of your diagnostic source.
You can configure Event Tracing for Windows (ETW) events to be sent to Application Insights as traces. First, install the Microsoft.ApplicationInsights.EtwCollector NuGet package. Then edit the "TelemetryModules" section of the ApplicationInsights.config file.
ETW events can only be collected if the process that hosts the SDK runs under an identity that's a member of Performance Log Users or Administrators.
For each source, you can set the following parameters:
You can call the Application Insights trace API directly. The logging adapters use this API.
TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault(); var telemetryClient = new TelemetryClient(configuration); telemetryClient.TrackTrace("Slow response - database01");
An advantage of TrackTrace is that you can put relatively long data in the message. For example, you can encode POST data there.
You can also add a severity level to your message. And, like other telemetry, you can add property values to help filter or search for different sets of traces. For example:
TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault(); var telemetryClient = new TelemetryClient(configuration); telemetryClient.TrackTrace("Slow database response", SeverityLevel.Warning, new Dictionary < < "database", "db.ID" >>);
Now you can easily filter out in Transaction Search all the messages of a particular severity level that relate to a particular database.
The Azure Monitor Log Handler allows you to export Python logs to Azure Monitor.
Instrument your application with the OpenCensus Python SDK for Azure Monitor.
This example shows how to send a warning level log to Azure Monitor.
import logging from opencensus.ext.azure.log_exporter import AzureLogHandler logger = logging.getLogger(__name__) logger.addHandler(AzureLogHandler(connection_string='InstrumentationKey=')) logger.warning('Hello, World!')
Run your app in debug mode or deploy it live.
In your app's overview pane in the Application Insights portal, select Transaction Search.
You can, for example:
If your application sends a lot of data and you're using the Application Insights SDK for ASP.NET version 2.0.0-beta3 or later, the adaptive sampling feature might operate and send only a portion of your telemetry. Learn more about sampling.
Find answers to common questions.
System.Diagnostics.Tracing has an Autoflush feature. This feature causes SDK to flush with every telemetry item, which is undesirable, and can cause logging adapter issues like delayed telemetry, an overloaded network, and inefficient transmission.
In Java codeless instrumentation, which is recommended, the logs are collected out of the box. Use Java 3.0 agent.
The Application Insights Java agent collects logs from Log4j, Logback, and java.util.logging out of the box.
You probably installed the logging adapter NuGet package without installing Application Insights. In Solution Explorer, right-click ApplicationInsights.config, and select Update Application Insights. You are prompted to sign in to Azure and create an Application Insights resource or reuse an existing one. It should fix the problem.
It can take a while for all the events and requests to get through the pipeline.
Several factors affect the amount of data that's retained. For more information, see the Limits section of the customer event metrics page.
Perhaps your application sends voluminous amounts of data and you're using the Application Insights SDK for ASP.NET version 2.0.0-beta3 or later. In this case, the adaptive sampling feature might operate and send only a portion of your telemetry. Learn more about sampling.