Analyze Sitecore logs with Application Insights

Abstract

Troubleshoot and improve performance using Microsoft Application Insights to analyze Sitecore logs.

Sitecore writes log information to Microsoft Application Insights® when running on the Microsoft Azure® App Service.

In Application Insights, you can identify error and warning messages, identify messages from specific roles and Sitecore instances, and search for specific log messages.

Using Application Insights, you can search for a particular word or subscription in Sitecore logs.

  1. Go to the Microsoft Azure® Portal and log on.

  2. On the Dashboard, click All resources, and select your Sitecore installation from the list of provisioned Azure resources.

  3. Click the Application Insights resource. When the page opens, on the toolbar, click Search.

  4. In the Search panel that appears on the right side, type your key search words in the Search box and click Enter.

    AnalyzeSitecoreLogs.PNG

    Note

    You can type, for example, Exception to search for exception messages in the logs. To search for a particular instance of an exception, you can also add an exception class name or method name where an exception might have occurred.

  5. At the top of the Search panel, click Filters.

  6. In the Filter panel that appears on the right side, under Event Types, clear all of the checkboxes except for the Trace and Exception checkboxes.

  7. To see the Trace events, at the bottom of the panel, click Update.

Using Application Insights, you can narrow down search results to a specific time range.

  1. In the Azure Portal, at the top of the Search page, click Time range.

  2. In the Time Range panel that appears on the right side, select the relevant recent time range (for example, 30 minutes or 1 hour), or specify a custom date and time range.

  3. At the bottom of the panel, click Update. The search results only show messages that fall within the specified time-span.

All Sitecore instances in a Sitecore environment share the same Application Insights resources. This means that you can use Application Insights to narrow down your search to a specific Sitecore role (for example, CD, CM, Processing, or Reporting):

  1. In the Azure portal, at the top of the Search page, click Filters.

  2. In the Filter panel that appears on the right side, expand the Role tab.

  3. Select the role you want visible in your search results.

  4. To see the log messages for the selected role, at the bottom of the panel, click Update.

Sitecore translates Log4net message severity levels into Application Insights Trace severity levels. The four supported severity levels are ErrorWarningInformational, and Verbose. For example, to search for Error and Warning messages only:

  1. In the Azure portal, at the top of the Search panel, click Filters.

  2. In the Filter panel that appears on the right side, expand the Severity level tab.

  3. Select the Error and Warning checkboxes.

  4. To see the log messages with severity levels of Error and Warning, at the bottom of the panel, click Update.

When the Search page displays log messages or other events, you can click on an item to see its details. An event details panel appears on the right side and contains information about the log message, including the following Trace properties:

  • The Web App Instance ID from the origin of the log message.

  • The message text of the log file. (To display the full message text on a new page, click the ellipsis button near the text.)

  • A full stack trace of the exception (for exception events only).

For a log message or exception, use the event details panel to navigate to related telemetry events, such as:

  • Events in the same logical operation, for example, in an ASP.NET request. This means you can see the URL of the request that caused the exception and also the log messages for a slow request.

  • Events with the same Web App Instance ID. This means you can identify which events happened in the same Sitecore instance as the original event.

  • Events that occur within 5 minutes before or after the original event. This means you can scan the entire Sitecore environment to identify which events happened close to the original event.

You can also use these navigation options to open new Search pages and explore what the Sitecore behavior was at the time a particular event occurred. This helps you to identify the root cause, an exception, or a particular behavior. The Microsoft Azure website provides more diagnostic search documentation about using the Application Insights Search functionality.