C#

How to setup recording & monitoring for C# applications

Requirements

  • C# project configuration

  • Any .NET application

  • Configured & installed RevDebug Server

To setup RevDeBug you will need to:

  1. Add RevDeBug dependency

  2. Configure the connection to RevDeBug Monitor

Adding RevDeBug dependency

Add RevDeBug NuGet repository to your solution. You can do that globally in Visual Studio settings:

Or by adding nuget.config file on solution level:

nuget.config
nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="rdb" value="https://nexus.revdebug.com/repository/nuget/" />
</packageSources>
</configuration>

Next use the NuGet package manager to add RevDeBug dependencies by adding the following NuGet packages:

After searching for a RevDeBug package, select both:

  • For .NET Core application:

    • RevDeBug.Net.Compilers.Toolset

    • RevDeBugAPM.Agent.AspNetCore

  • For Standard .NET Framwork application:

    • RevDeBug.Net.Compilers.Toolset

    • RevDeBugAPM.Agent.AspNet

Configure the connection to RevDeBug Monitor

Add Directory.Build.props file on solution level

Directory.Build.props
Directory.Build.props
<Project>
<PropertyGroup Condition="'$(RevDeBugDisableNuget)' != 'true'">
<RevDeBugActive>true</RevDeBugActive>
<UseRevDeBugOnThisProject>true</UseRevDeBugOnThisProject>
<RevDeBugStateStorageType>CrashRecorder</RevDeBugStateStorageType>
<SendToServer>true</SendToServer>
<RecorderAddress>127.0.0.1</RecorderAddress>
<RecorderTCPPort>42734</RecorderTCPPort>
<RevDeBugForceTLS>false</RevDeBugForceTLS>
<ImportGitInfo>true</ImportGitInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
<isNetCore>true</isNetCore>
</PropertyGroup>
</Project>

There are several configurable fields:

  • RecorderTCPPort - Default port to connect to RevDeBug DevOps Monitor.

  • RecorderAddress - Here you have to enter the IP address or hostname of the recording servers (if you are using Docker, use Ifconfig command to get an IP address)

  • RevDeBugForceTLS - Forces TLS connection with the server. Set this to true if your RevDeBug DevOps Monitor instance has been configured to work with a SSL certificate.

  • RevDeBugUseWarningOnFailedSend - Replaces error messages with warnings for metadata transfer process. Useful for non-mandatory builds.

Both these fields are used to connect to the data repository. In most cases, it is a RevDeBug server - a place to store recordings.

  • RevDeBugActive - Fast way to disable revdebug on your solution.

  • RevDeBugStateStorageType - this field is crucial for application performance. There are three values that you can use here:

    • Continuous - means that your application will be permanently connected to the RevDeBug server. Even if you select standby or emergency recording mode, the application will be connected. It will not stream data, but there will be a slight decrease in performance.

    • OnEvent - works on the contrary. The application connects to the RevDeBug server only for a specific event. And this event must come from the application. For example, a failure or a particular method or object you want to record

    • Noop - this field is handy when you want to connect to the RevDeBug server only in case of an emergency, or you care about performance. For example, you can build your application with RevDeBug, prepare all events that should be recorded, but until you change this setting, nothing will be recorded.

Configure tracing

Add skyapm.json to startup project and make sure its copied to output directory

skyapm.json
skyapm.json
{
"SkyWalking": {
"ServiceName": "ServiceName",
"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": "[address]:11800",
"Timeout": 10000,
"ConnectTimeout": 10000,
"ReportTimeout": 600000,
"ForceTLS": false
}
}
}
}

and set [address] to point to your record server instance. If your RevDeBug DevOps Monitor instance has been configured to work with a SSL certificate, set ForceTLS to true.

IMPORTANT NOTE: When you run ASP.NET Core application set environment variable ASPNETCORE_HOSTINGSTARTUPASSEMBLIES to RevDeBugAPM.Agent.AspNetCore