> For the complete documentation index, see [llms.txt](https://docs.sealights.io/knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/.net-core-agent/capturing-coverage-from-the-application/capturing-coverage-from-the-app-process.md).

# Capturing coverage from the app process

There are **two ways to capture coverage from application or service processes** with the SeaLights .NET Agent:

1. Run the process with the agent by using the **run** command.
2. Run the agent as a **background listener**.

Use the background listener flow when you cannot change the original startup command.

## Running the process with `run` <a href="#running-the-process-with-the-sealights-.net-core-agent-using-run-option" id="running-the-process-with-the-sealights-.net-core-agent-using-run-option"></a>

To capture coverage from a single application, start it through the agent.

{% tabs %}
{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
.\sl-dotnet-agent\SL.DotNet.exe run --buildSessionIdFile buildSessionId.txt --labId "<lab-id>" --includeNamespace "MyCompany.*" --instrumentationMode coverage --target "C:\MyApplication\App.exe" --workingDir "C:\WorkingDir" --targetArgs "-Flag1 true"
```

{% endcode %}
{% endtab %}

{% tab title="Bash" %}
{% code overflow="wrap" lineNumbers="true" %}

```bash
./sl-dotnet-agent/SL.DotNet run --buildSessionIdFile buildSessionId.txt --labId "<lab-id>" --includeNamespace "MyCompany.*" --instrumentationMode coverage --target "/opt/my-app/MyApplication" --workingDir "/opt/my-app" --targetArgs "--flag1 true"
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
This replaces the regular startup command for the application you want to profile.
{% endhint %}

{% hint style="success" %}
When the flow starts correctly, **Cockpit → Live Agents Monitor** shows the `testListener` and `Profiler` entries for the application.
{% endhint %}

{% hint style="info" %}
See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/.net-core-agent/command-reference.md#starting-background-test-listener) for full parameter details.
{% endhint %}

## Running the agent as a background listener <a href="#running-the-sealights-.net-core-agent-as-a-background-listener" id="running-the-sealights-.net-core-agent-as-a-background-listener"></a>

Use this flow when the application command must stay unchanged.

### Start the background listener <a href="#starting-the-sealights-.net-core-agent-background-listener" id="starting-the-sealights-.net-core-agent-background-listener"></a>

Start the listener with a unique session key.

{% tabs %}
{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
.\sl-dotnet-agent\SL.DotNet.exe startBackgroundTestListener --buildSessionIdFile buildSessionId.txt --labId "<lab-id>" --includeNamespace "MyCompany.*" --testListenerSessionKey SL_CovCollectorAgent
```

{% endcode %}
{% endtab %}

{% tab title="Bash" %}
{% code overflow="wrap" lineNumbers="true" %}

```bash
./sl-dotnet-agent/SL.DotNet startBackgroundTestListener --buildSessionIdFile buildSessionId.txt --labId "<lab-id>" --includeNamespace "MyCompany.*" --testListenerSessionKey SL_CovCollectorAgent
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Set the agent as a profiler <a href="#setting-the-sealights-.net-core-agent-as-a-profiler" id="setting-the-sealights-.net-core-agent-as-a-profiler"></a>

Set these environment variables in the same session that starts the application.

{% tabs %}
{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
$Env:CORECLR_ENABLE_PROFILING = "1"
$Env:CORECLR_PROFILER = "{01CA2C22-DC03-4FF5-8350-59E32A3536BA}"
$Env:CORECLR_PROFILER_PATH_32 = "C:\Sealights\agent\SL.DotNet.ProfilerLib.Windows_x86.dll"
$Env:CORECLR_PROFILER_PATH_64 = "C:\Sealights\agent\SL.DotNet.ProfilerLib.Windows_x64.dll"
$Env:SL_CollectorId = "SL_CovCollectorAgent"
$Env:SL_LogDir = "C:\Sealights\logs"
$Env:SL_LogLevel = "6"
```

{% endcode %}
{% endtab %}

{% tab title="Bash" %}
{% code overflow="wrap" lineNumbers="true" %}

```bash
export CORECLR_ENABLE_PROFILING=1
export CORECLR_PROFILER="{3B1DAA64-89D4-4999-ABF4-6A979B650B7D}"
export CORECLR_PROFILER_PATH_32="/usr/local/lib/libSL.DotNet.ProfilerLib.Linux.so"
export CORECLR_PROFILER_PATH_64="/usr/local/lib/libSL.DotNet.ProfilerLib.Linux.so"
export SL_CollectorId="SL_CovCollectorAgent"
export SL_LogDir="/tmp/logs"
export SL_LogLevel="6"
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="warning" %}

* Ensure the variables specifying the profiler path are correct, given where you installed the agent binaries (for example: `CORECLR_PROFILER_PATH_32=/usr/local/lib/libSL.DotNet.ProfilerLib.Linux.so`)
* You should **unset** the environment variables before running any process that you **do not want** to capture coverage from
* Prefer process-scoped variables instead of persistent machine or user variables.
  {% endhint %}

{% hint style="success" %}
After you start the application with its normal command, **Cockpit → Live Agents Monitor** shows the `testListener` and `Profiler` entries.
{% endhint %}

### Stop the background listener <a href="#stopping-the-sealights-.net-core-agent-background-listener" id="stopping-the-sealights-.net-core-agent-background-listener"></a>

When coverage collection is complete, stop the listener with the same session key.

{% tabs %}
{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
.\sl-dotnet-agent\SL.DotNet.exe stopBackgroundTestListener --labId "<lab-id>" --testListenerSessionKey SL_CovCollectorAgent
```

{% endcode %}
{% endtab %}

{% tab title="Bash" %}
{% code overflow="wrap" lineNumbers="true" %}

```bash
./sl-dotnet-agent/SL.DotNet stopBackgroundTestListener --labId "<lab-id>" --testListenerSessionKey SL_CovCollectorAgent
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="info" %}
See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/.net-core-agent/command-reference.md) for full parameter details.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/.net-core-agent/capturing-coverage-from-the-application/capturing-coverage-from-the-app-process.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
