Uredi

Enable the .NET Profiler for web apps on a Windows virtual machine

Note

We recommend that you use the Azure Az PowerShell module to interact with Azure. To get started, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

Application Insights Profiler for .NET captures traces that show which code paths slow down your web app when it's running under load. With this information, you can pinpoint the methods that create performance bottlenecks and focus your optimization work where it has the most effect.

In this article, you enable Profiler for .NET for a web app that runs on a Windows virtual machine (VM) or virtual machine scale set in Azure. Profiler for .NET doesn't support on-premises servers.

In this article, you learn how to:

  • Add the Application Insights SDK to your application.
  • Confirm the latest stable release of the Application Insights SDK.
  • Enable the .NET Profiler by using Visual Studio and an Azure Resource Manager template (ARM template), PowerShell, or Azure Resource Explorer.

Prerequisites

Add the Application Insights SDK to your application

  1. Open your ASP.NET Core project in Visual Studio.

  2. Select Project > Add Application Insights Telemetry.

  3. Select Azure Application Insights, then select Next.

  4. Select the subscription where your Application Insights resource lives, then select Next.

  5. Select where to save the connection string, then select Next.

  6. Select Finish.

Note

For full instructions, including how to enable Application Insights on your ASP.NET Core application without Visual Studio, see Monitor .NET and Node.js applications.

Confirm the latest stable release of the Application Insights SDK

  1. Go to Project > Manage NuGet Packages.

  2. Select Microsoft.ApplicationInsights.AspNetCore.

  3. On the side pane, select the latest version of the SDK from the dropdown list.

  4. Select Update.

    Screenshot that shows where to select the Application Insights package for update.

Enable the .NET Profiler on a Windows VM or virtual machine scale set

Enable Profiler in one of these ways:

  • Within your ASP.NET Core application by using an ARM template and Visual Studio. Recommended.
  • By using a PowerShell command.
  • By using Azure Resource Explorer.

Using an ARM template and Visual Studio is the recommended method for enabling the .NET Profiler on a Windows VM or virtual machine scale set.

Install the Azure Diagnostics extension

  1. Choose which ARM template to use:

  2. In the template, locate the resource of type extension.

  3. In Visual Studio, open the arm.json file that the Application Insights SDK added to your ASP.NET Core application.

  4. Add the resource type extension from the template to the arm.json file to set up a VM or virtual machine scale set with Azure Diagnostics.

  5. In the WadCfg node, add your Application Insights connection string to MyApplicationInsightsProfilerSink.

    "WadCfg": {
      "SinksConfig": {
        "Sink": [
          {
            "name": "MyApplicationInsightsProfilerSink",
            "ApplicationInsightsProfiler": "YOUR_APPLICATION_INSIGHTS_CONNECTION_STRING"
          }
        ]
      }
    }
    
  6. Deploy your application.

Enable the IIS HTTP Tracing feature

If the application runs through Internet Information Services (IIS), enable the IIS HTTP Tracing Windows feature:

  1. Establish remote access to the environment.

  2. Use the Add Windows features window, or run the following command in PowerShell as administrator:

    Enable-WindowsOptionalFeature -FeatureName IIS-HttpTracing -Online -All
    

    If you can't establish remote access, use the Azure CLI to run the following command:

    az vm run-command invoke -g YOUR_RESOURCE_GROUP -n YOUR_VM --command-id RunPowerShellScript --scripts "Enable-WindowsOptionalFeature -FeatureName IIS-HttpTracing -Online -All"
    
  3. Deploy your application.

Next step