.NET

TracesMetricsApp LogsCustom LogsProfiling

This guide walks you through setting up Application Performance Monitoring (APM) on a .NET application. These instructions can also be found on the Installation page in your Middleware Account. View example code here.

Prerequisites

1 Infra Agent

To install the Infra Agent, see our Installation Guide.

2 .NET Version

.NET version 6+. Check your .NET version with the following command:

Install

Step 1: Setup Middleware .NET Project

Download the latest Middleware.dll and add the following code in the .csproj file.

Step 2: Install .NET APM Package

Linux
Windows
Docker
Kubernetes

Run the following command in your terminal

Install core files

Enable execution for the instrumentation script

Execute the following command run your .NET application:

Run the following command in powershell your terminal

Execute the script

Register the .NET service name

Run your application with instrumentation.

If you are running your .NET app as a container, you can include all this steps in your Dockerfile as mentioned below

Add the following environment variables to your container:

The DOCKER_BRIDGE_GATEWAY_ADDRESS is the IP address of the gateway between the Docker host and bridge network. This is 172.17.0.1 by default. Learn more about Docker bridge networking here

Specify your HTTP ports and URL with the following:

This only applies to .NET projects using the ASP framework.

Dockerfile

If you are running your .NET app as a Kubernetes container, you can include all this steps in your Dockerfile as mentioned below

Add the following environment variables to your container:

The default namespace for running the Middleware agent is mw-service.mw-agent-ns.svc.cluster.local.

Sending Custom Data [Optional]

Enable Custom Logs

Add the following functions:

Add packages to YourApp.csproj file

Enable Logs in your project.cs file

Continuous Profiling

Continuous profiling captures real-time performance insights from your application to enable rapid identification of resource allocation, bottlenecks, and more. Navigate to the Continuous Profiling section to learn more about using Continuous Profiling with the .NET APM.

.NET Nuget Packge APM Configuration

TracesMetricsApp LogsCustom LogsProfiling

Step 1: Install the Required Package

Add the Middleware package to your .NET project by running the following command using CLI:

OR

If you are using Visual Studio IDE in Windows, then you can install it by going to below given path.

PATH - Tools > Nuget Package Manager > Manage Nuget Packages for Solutions > Browse

Now, search for MW.APM and Install the nuget package.

Installing Nuget Package in Visual Studio

Step 2: Add Code Configuration

Add the following code to your Program.cs file:

Step 3: Configure Your Middleware Account Information

Add the following to your appsettings.json file:

appsetting.json Config AttributeDescription
ApiKeyMW API Key of your account. It is required field.
TargetURLMW Target URL of your account. It is required field.
ServiceNameIf this key not provided then default value unknown_service:dotnet.
ProjectNameIf this key not provided then default value blank.
ConsoleExporterThis key useful when user wants to debug APM. If this key not provided then default value false.
ExcludeLinksIf user wants to exclude some APIs generated using Http client from tracing. If this key not provided then default value empty list.
ApmCollectMetricsKey for enabling Metrics Instrumentation. If this key not provided then default value true.
ApmCollectTracesKey for enabling Traces Instrumentation. If this key not provided then default value true.
ApmCollectLogsKey for enabling Logs Instrumentation. If this key not provided then default value true.

This is a one-time configuration. After these configuration changes are made, each time the .NET app will run, the .NET instrumentation will also run.

Need assistance or want to learn more about Middleware? Contact our support team in Slack.