Skip to content

Install the Lightrun .NET agent

The Lightrun agent is at the core of the Lightrun platform. It's the component that communicates requests for runtime observability to your running code, and gathers and relays the requested data back to the Lightrun Server, and eventually the developer's IDE.

Before running the agent, it must be installed on the system where your code to be monitored is running. In addition, you will need to provide credentials which will be used when the agent connects to the Lightrun server.

System requirements

Lightrun for .NET supports Windows and Linux. For more information, please check out the .NET agent system requirements here.

Direct installation

  1. Open a terminal and change to the working directory where your project is located.
  2. Install the .NET agent with the NuGet package manager:

    dotnet add package Lightrun

  3. Add the Lightrun agent to the top of your application’s main file. (i.e., Program.cs file):

    using Lightrun;

  4. Add the following lines of code to the entry point of your application.

    LightrunAgent.Start(new AgentOptions {
        Secret = "<LIGHTRUN_SECRET>",

    Getting Company Details

    You can get your <LIGHTRUN_SECRET> key by logging into the Management Portal and inspecting the Set up an agent section.


    Other configuration parameters can also be passed here. For example, add the ServerUrl parameter to the LightrunAgent.Start command when using Lightrun On premise.

      LightrunAgent.Start(new AgentOptions {
          Secret = "<LIGHTRUN_SECRET>",
          ServerUrl = “<server_url>”
  5. Make sure your project file (.csproj) includes the following:


  6. Set the required environment variables for automatic instrumentation to attach to your application. For a list of the variables, see the 'Required Environment Variables' section.

  7. Run your application.

Required Environment Variables

For the Lightrun agent to attach to the .NET runtime, set the following environment variables.

The Lightrun package provides a script to simplify setting these environment variables on Linux. When you build your project, the script is copied to the output directory, and to locate it, we recommend a straightforward search for The script can be used as follows:


PUBLISH_DIRECTORY should be changed to the actual directory where the web app is published.

Set the variables manually

.NET Core on Linux


.NET Core on Alpine Linux


.NET Core on Windows


.Net Framework



PUBLISH_DIRECTORY should be changed to the actual directory where the web app is published.

Last update: July 21, 2024