Implementing Application Performance Monitoring with SkyWalking in .NET Core Applications

Deploying Elasticsearch with Docker

To begin our monitoring setup, we'll first deploy Elasticsearch which will serve as the storage backend for SkyWalking:

docker run -d -p 9200:9200 -p 9300:9300 --name elastic-search \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms128m -Xmx256m" \
elasticsearch:7.12.0

Deploying SkyWalking Components

SkyWalking OAP Server

Next, we'll deploy the OAP (Observability Analysis Platform) server. Remember to replace the IP address with your own:

docker run --name oap-server \
--restart always \
-p 11800:11800 -p 12800:12800 -d \
-e TZ=Asia/Shanghai \
-e SW_ES_USER= \
-e SW_ES_PASSWORD= \
-e SW_STORAGE=elasticsearch \
-e SW_STORAGE_ES_CLUSTER_NODES=192.168.1.22:9200 \
-v /etc/localtime:/etc/localtime:ro \
apache/skywalking-oap-server:9.3.0

SkyWalking UI

Now, let's deploy the UI component for visualizing our monitoring data:

docker run -d \
--name sw-ui \
--restart always \
-p 8080:8080 \
--link oap-server:oap-server \
-e TZ=Asia/Shanghai \
-e SW_OAP_ADDRESS=http://oap-server:12800 \
-v /etc/localtime:/etc/localtime:ro \
apache/skywalking-ui:9.3.0

After deployment, verify that the containers are running and access the UI by opening your browser to the server's IP on port 8080.

Configurinng a .NET 6 Web API Project with SkyWalking

Creating the Configuration File

In your project root directory, create a skyapm.json file with the following content:

{
  "SkyWalking": {
    "ServiceName": "my-api-service",
    "Namespace": "",
    "HeaderVersions": [
      "sw8"
    ],
    "Sampling": {
      "SamplePer3Secs": -1,
      "Percentage": -1.0
    },
    "Logging": {
      "Level": "Information",
      "FilePath": "logs\\skyapm-{Date}.log"
    },
    "Transport": {
      "Interval": 3000,
      "ProtocolVersion": "v8",
      "QueueSize": 30000,
      "BatchSize": 3000,
      "gRPC": {
        "Servers": "192.168.1.22:11800",
        "Timeout": 10000,
        "ConnectTimeout": 10000,
        "ReportTimeout": 600000,
        "Authentication": ""
      }
    }
  }
}

Modifying Program.cs

Add the following code to your Program.cs file:

Environment.SetEnvironmentVariable("ASPNETCORE_HOSTINGSTARTUPASSEMBLIES", "SkyAPM.Agent.AspNetCore");
Environment.SetEnvironmentVariable("SKYWALKING__SERVICENAME", "my-api-service");

Updating launchSettings.json

In your launchSettings.json, add these environment variables (replace "my-api-service" with your desired service name):

"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "SkyAPM.Agent.AspNetCore;Common", 
"SKYWALKING__SERVICENAME": "my-api-service"

Deploying the Example Service

Creating and Publishing the Docker Image

  1. Publish your .NET project
  2. On Windows, use Docker Desktop to build an image and save it to a local file
  3. Transfer the image file to your CentOS server
  4. Load the image on the server

Running the Container

Start your service container with the following command:

docker run -d --name my-api-container -p 8860:80 --restart always my-api-image:1.0

Verifying the Setup

Open your browser and navigate to the SkyWalking UI. Note that there might be a delay in data collection, so wait a few moments before expecting to see your service data. After accessing your API endpoints, you should be able to see the traces and metrics in the SkyWalking interface.

Tags: .NET Core skywalking Application Performance Monitoring docker elasticsearch

Posted on Mon, 06 Jul 2026 16:14:09 +0000 by thaven