Documentation forSolarWinds Observability SaaS

Send logs from .NET/C# applications (Papertrail)

You can send logs from a .NET or C# application directly to SolarWinds Papertrail, without installing an agent or log forwarder on the host. Use either of the following methods:

  1. Syslog (TLS)

  2. HTTPS bulk

To get a destination and token in Papertrail, add a new log destination. The ingestion token is generated along with the destination. Use the collector endpoints for your account's region:

  • Syslog (TLS): syslog.collector.<REGION>.cloud.solarwinds.com:6514

  • HTTPS: https://logs.collector.<REGION>.cloud.solarwinds.com/v1/logs/bulk

Replace <REGION> with the data center your organization uses: na-01, eu-01, or ap-01.

Send logs with Syslog (TLS)

To send logs from .NET/C# applications with Syslog (TLS), install the following packages:

dotnet add package NLog
dotnet add package NLog.Targets.Syslog

Then, place NLog.config in the project root, and set it to copy to the output directory.

<ItemGroup>
  <None Update="NLog.config">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <extensions>
    <add assembly="NLog.Targets.Syslog"/>
  </extensions>

  <targets>
    <target xsi:type="Syslog" name="swo">
      <messageCreation>
        <facility>User</facility>
        <rfc>Rfc5424</rfc>
        <rfc5424>
          <hostname>${machinename}</hostname>
          <appName>my-service</appName>
          <structuredData>
            <sdElements>
              <sdElement>
                <sdId>solarwinds@41058</sdId>
                <sdParams>
                  <sdParam name="token" value="${environment:SWO_TOKEN}"/>
                </sdParams>
              </sdElement>
            </sdElements>
          </structuredData>
        </rfc5424>
      </messageCreation>
      <messageSend>
        <protocol>Tcp</protocol>
        <tcp>
          <server>syslog.collector.${environment:REGION}.cloud.solarwinds.com</server>
          <port>6514</port>
          <tls>
            <enabled>true</enabled>
          </tls>
        </tcp>
      </messageSend>
    </target>
  </targets>

  <rules>
    <logger name="*" minlevel="Debug" writeTo="swo"/>
  </rules>
</nlog>

${machinename} resolves to System.Environment.MachineName at runtime.
${environment:SWO_TOKEN} and ${environment:REGION} are read from environment variables. They do not require startup code.

Using other logging libraries

Serilog users

Serilog does not have an RFC 5424 syslog sink that supports custom structured data elements out of the box. Serilog users can either use NLog as the syslog transport by wiring it in as a Serilog sink via Serilog.Sinks.NLog or use the HTTPS bulk option.

Microsoft.Extensions.Logging users

NLog integrates with Microsoft.Extensions.Logging via the NLog.Extensions.Logging package. Once registered as the MEL provider, the same NLog.config applies with no further changes to the code required.

TLS certificates

No manual trust store configuration is required. The Papertrail collector certificate (*.cloud.solarwinds.com) is issued by Amazon RSA 2048 M04, which is included in .NET's default CA bundle on all supported platforms. The <tls><enabled>true</enabled></tls> element uses the system trust store automatically.

Send logs with HTTPS bulk

When sending logs from .NET/C# applications with HTTPS bulk, the host/program is found in the X-Otel-Resource-Attr header, and the ingestion token is in the Authorization: Bearer header. The severity can be set as a field in the payload and arrives as a searchable json.* field only.

Before sending logs with HTTPS bulk, make sure the following package is installed:

dotnet add package Serilog
HttpClient and System.Text.Json are part of the .NET runtime, so no additional packages are required.

Next, add a custom Serilog sink (SwoHttpSink.cs) to your project by copying the following code:

using Serilog.Core;
using Serilog.Events;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

public class SwoHttpSink : ILogEventSink
{
    private static readonly HttpClient _http = new();
    private readonly string _url;

    public SwoHttpSink(string url, string token, string hostname, string appName)
    {
        _url = url;
        _http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
        _http.DefaultRequestHeaders.TryAddWithoutValidation("X-Otel-Resource-Attr", $"host.name={hostname},service.name={appName}");
    }

    public void Emit(LogEvent logEvent)
    {
        var record = new
        {
            timestamp = logEvent.Timestamp.UtcDateTime.ToString("o"),
            severity  = logEvent.Level.ToString().ToLower(),
            message   = logEvent.RenderMessage() + (logEvent.Exception is { } ex ? $"{ex}" : ""),
        };
        var body    = JsonSerializer.Serialize(record) + "";
        var content = new StringContent(body, Encoding.UTF8, "application/xndjson");
        _ = _http.PostAsync(_url, content);
    }
}

Then, configure Serilog to use the sink:

using Serilog;

var logger = new LoggerConfiguration()
    .MinimumLevel.Debug()
    .WriteTo.Sink(new SwoHttpSink(
        url:      $"https://logs.collector.{Environment.GetEnvironmentVariable("REGION")}.cloud.solarwinds.com/v1/logs/bulk",
        token:    Environment.GetEnvironmentVariable("SWO_TOKEN")!,
        hostname: System.Net.Dns.GetHostName(),
        appName:  "my-service"))
    .CreateLogger();

logger.Information("Application started");
logger.Error(ex, "Something went wrong");

await Log.CloseAndFlushAsync();

The severity field in the JSON payload is searchable in the Logs Explorer as json.severity. All other JSON fields are searchable as json.*.

Additional info

  • host.name and service.name are set from the X-Otel-Resource-Attr header and apply to the whole request batch. They are not per-record.
  • The /v1/logs/bulk endpoint assigns a fixed severity of info to all records in the Logs Explorer. The actual level is stored in json.severity and is searchable.
  • SwoHttpSink sends one HTTP request per log event. For high-throughput applications, consider batching records before sending.
  • Exception stack traces are appended to the message field and are fully readable in the Logs Explorer.

If your application cannot connect directly to the Papertrail collector, write logs to a local file and use the host's syslog daemon to forward them to Papertrail over TLS. SolarWinds Observability SaaS supports rsyslog on Linux and NXLog on Windows for this purpose. See Send logs using syslog (SolarWinds Observability SaaS) for configuration instructions.

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.