---
title: "Enabling APM on a .NET Web App"
slug: "enabling-apm-on-a-net-web-app"
updated: 2023-11-15T03:58:11Z
published: 2023-11-15T03:58:11Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Enabling APM on a .NET Web App

This guide aims to enable Retrace APM monitoring on a sample .NET 6 MVC app on Windows. The app used in this example is based on the MVC template for .NET 6 and has logging events configured in some of the pages. [Serilog (2.12)](/v1/docs/errors-and-logs-serilog) is primarily used as the logger, with [StackifyLib (direct API logging)](/v1/docs/logs-using-stackify-api-for-net) in some events.

- Home - Just a bare Home page that logs the following:
  - Debug log `"#index - accessed"` (Serilog)
  - Error log `"Test exception #test-plain"` (StackifyLib Direct API)
- Privacy - page that logs a debug log `"#privacy - accessed"`
- Test - intermittently generates the following log events:
  - Info log `"Nothing happened, really #nothing"`
  - Error log `"An exception was #caught"`
  - Info log `"App carries on, #finally"`
  - Error log `"App raised an #uncaught exception"`

This guide will also walk through the steps of how to host the .NET application in IIS on Windows.

## Set Up the Sample App

1. Download the sample Dotnet app from [https://github.com/stackify/example-apps](https://github.com/stackify/example-apps) ("sample-dotnet" folder) and deploy it on IIS* (*or run it later as a self-hosted app*). To deploy on IIS:
  1. Extract the folder **"sample-dotnet"** to C:\inetpub\wwwroot. At the end of this step, you should have all the sample web files in C:\inetpub\wwwroot\sample-dotnet\ (*any folder name can be used here*). In the succeeding screenshots, I have renamed this folder to "SampleApp", e.g. C:\inetpub\wwwroot\SampleApp.
  2. Open up IIS Manager (search from start menu)
  3. Expand the current server until you see Application Pools and Sites
  4. Right-click on "Sites" and select "Add Website"  

![deployOnIIS_1.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/deployOnIIS_1.png)
  5. Fill-in the details such as the site name, physical path (*from step 1a*), IP address (*"all unassigned" can be used*), and Port (*make sure it is not the same with an existing site*).  

![deployOnIIS_2.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/deployOnIIS_2.png)

          Port Configuration

          

The image above uses port **80**, however, there may already be an existing site in your IIS environment that uses this port. To check, browse **http://localhost:80** in your web browser and see if a site loads. If it's already in use, try another port such as *81*. You can do the same check by substituting **80** above with the port number you intend to use.

1. Open the `Stackify.json` file bundled with the app. Adjust the app and environment properties as required. These names are mainly used to identify the app in Retrace.  

![stackifyJson.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/stackifyJson.png)

![stackifyJson_edit.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/stackifyJson_edit.png)

```
{
  "AppName": "Stackify Sample Dotnet App",
  "Environment": "My Environment",
  "CaptureAllExceptions": true
}
```

1. Open the `appsettings.json` file of the app. The Stackify properties in this config file are for logging integration with Retrace. Supply your API key under the Stackify.ApiKey property. It’s important that the application and environment names match those from the Stackify.json file in order to correctly match logs with an app entry back in your Retrace account.  

![appsettingsJson.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/appsettingsJson.png)

```
{
  ...
  "Stackify": {
    "ApiKey": "Your-API-Key-Here",
    "AppName": "Stackify Sample Dotnet App",
    "Environment": "My Environment"
  }
  ...
}
```

          
          

Forgot your API key? Visit this [link](https://s1.stackify.com/Onboarding/InstallGuide/InstallRetrace) on your account to get the key.

1. Run the app on IIS, or launch the app's executable. You should see a similar page below when you visit the Test page of the app at http://localhost/Test, for example:  

![sampleAppPage.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/sampleAppPage.png)

          Port Access

          

The image above shows http://localhost:**8081**/Test -- your setup could be different so make sure you specify the actual port configured back in **step 1e**. If you run the app's main executable instead of hosting it in IIS, then it will run on port 5000 by default, e.g. http://localhost:5000/Test.

          *Pre-requisite check

          

The sample app requires .NET 6 hosting runtime installed on the machine.

## Install Retrace

1. Download the latest version of the Stackify (Retrace) agent from: [https://s1.stackify.com/Account/AgentDownload/Index](https://s1.stackify.com/Account/AgentDownload/Index)
2. Start the installer.  

2.1 The installer will check and install (if missing) .NET Framework 4.6.2 and Visual C++ 2013/2017 libraries. A system restart may be required if .NET Framework 4.6.2 has to be installed.  

2.2 Supply your Retrace API Key  

2.3 Options: Java profiling - if you plan to instrument Java apps; Legacy profiler - if you want to monitor apps that have outdated .NET runtime targets;  

2.4 Automatic IIS Restart - auto-restart IIS (and its worker processes) after the agent is installed.

          Note:

          

Restarting IIS worker processes is important to get the profiler attached, so either you restart IIS after the installation or restart it manually at a later time.

1. The server where the agent is installed should appear in your Retrace account after the installation.

## Post-installation checks

The following environment variables should be automatically registered after installing the agent:

```
COR_ENABLE_PROFILING=1
COR_PROFILER={cf0d821e-299b-5307-a3d8-b283c03916da}
CORECLR_ENABLE_PROFILING=1
CORECLR_PROFILER={cf0d821e-299b-5307-a3d8-b283c03916da}
StackifyPath=C:\Program Files (x86)\Stackify
```

          Note:

          

There are cases when IIS does not pick these up even after restarting the service, so a server restart may be required.

## Restart IIS

          Note:

          

If you enabled the IIS Restart option during installation, or had to restart the server, then you may skip this step.

You can restart IIS by either executing `iisreset` in an elevated terminal, or via IIS Manager.

## Send requests to your application

When the app receives requests, the profiler immediately goes into action. You can check the following paths below after sending 1-2 requests:

1. `C:\ProgramData\Stackify\Agent\debug\` - this is where profiler debug logs are generated. The debug logs are named `clrprofiler_debug_*.log` and will reflect the app's main assembly or executable. The file will also indicate whether profiling is allowed or not. ![profilerDebugLog.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/profilerDebugLog.png)
2. `C:\ProgramData\Stackify\Agent\log\` - if everything works, you should see trace logs generated in this path. The Retrace agent reads the traces here and uploads them to our platform.

## See APM data reflected on Retrace.

On average, APM initially shows up around 15 minutes after confirming that traces have been generated. Succeeding data should be reported within 2-5 minutes. ![retrace_apmDashboard.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/retrace_apmDashboard.png)

Logs will appear on the logs viewer. Errors/exceptions are considered as logs, but these also have a dedicated view under the "Errors" tab. ![retrace_logDashboard.png](https://cdn.document360.io/3fcaf473-a1ef-4778-aa2c-fd28411c2b01/Images/Documentation/retrace_logDashboard.png)

To learn more about viewing your application's data, be sure to check out [documentation on the App Dashboard](/v1/docs/account-application-dashboard-overview).
