Serilog.Sinks.LogStream 1.1.3

dotnet add package Serilog.Sinks.LogStream --version 1.1.3
                    
NuGet\Install-Package Serilog.Sinks.LogStream -Version 1.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Serilog.Sinks.LogStream" Version="1.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Serilog.Sinks.LogStream" Version="1.1.3" />
                    
Directory.Packages.props
<PackageReference Include="Serilog.Sinks.LogStream" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Serilog.Sinks.LogStream --version 1.1.3
                    
#r "nuget: Serilog.Sinks.LogStream, 1.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Serilog.Sinks.LogStream@1.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Serilog.Sinks.LogStream&version=1.1.3
                    
Install as a Cake Addin
#tool nuget:?package=Serilog.Sinks.LogStream&version=1.1.3
                    
Install as a Cake Tool

Serilog.Sinks.LogStream

πŸ“‘πŸͺ΅ A Serilog sink that writes events to a LogStream server.

GitHub license Time tracker

Serilog.Sinks.LogStream logo

Documentation: GitHub Pages


Table of content


Features

  • Batched delivery β€” events are sent in batches to POST /api/logs using Serilog's built-in batching.
  • Structured β€” rendered message, message template, category, level, properties, exception chain and trace ID, so events can be searched, grouped by template and followed by trace in the LogStream UI.
  • HTTP or UDP β€” batches over HTTP with retries, or HMAC-signed fire-and-forget UDP datagrams for high-volume logging, with oversized events falling back to HTTP.
  • Both storage modes β€” file storage (shared API_SECRET + appKey) and MariaDB storage (per-app X-Api-Key / X-Api-Token).
  • Resilient β€” transient failures (network errors, timeouts, 408, 429, 5xx) are retried with back-off; permanent rejections are reported to SelfLog and dropped.
  • Configurable from code or appsettings.json β€” works with Serilog.Settings.Configuration.
  • Trace-aware β€” Serilog 4 captures Activity.Current, so the trace_id and span_id flow to LogStream.

CI/CD

Build and tests Release Last commit
Build and Test Release GitHub last commit

Code Quality

codecov


.NET support

Target framework Supported
.NET Standard 2.0 (.NET Framework 4.6.2+, .NET Core 2.0+) βœ…
.NET 8.0 βœ…
.NET 9.0 βœ…
.NET 10.0 βœ…

Requires Serilog 4 or later.


Installation

GitHub Releases

GitHub last release GitHub All Releases

Download the latest .nupkg from the Releases page.

NuGet package manager

Package Version Downloads
Serilog.Sinks.LogStream Serilog.Sinks.LogStream NuGet Version Serilog.Sinks.LogStream NuGet Downloads
dotnet add package Serilog.Sinks.LogStream

Usage

File storage

The server has one shared API_SECRET; name the application with appKey:

Log.Logger = new LoggerConfiguration()
    .WriteTo.LogStream(
        serverUrl: "https://logs.example.com",
        appId: "production",
        appKey: "billing-api",
        apiSecret: Environment.GetEnvironmentVariable("LOGSTREAM_API_SECRET"))
    .CreateLogger();

MariaDB storage

Each application has its own key and token (X-Api-Key / X-Api-Token); the key is the app key:

Log.Logger = new LoggerConfiguration()
    .WriteTo.LogStream(
        serverUrl: "https://logs.example.com",
        appId: "production",
        apiKey: "billing-api",
        apiToken: Environment.GetEnvironmentVariable("LOGSTREAM_API_TOKEN"))
    .CreateLogger();

UDP

For high-volume logging the server can also take HMAC-signed UDP datagrams (UDP_PORT, default 8082/udp), which skip the TCP handshake, TLS and HTTP parsing. Set transport to Udp; the same credentials sign every packet (apiToken, or apiSecret in file storage), and the secret never travels on the wire:

Log.Logger = new LoggerConfiguration()
    .WriteTo.LogStream(
        serverUrl: "https://logs.example.com",
        appId: "production",
        apiKey: "billing-api",
        apiToken: Environment.GetEnvironmentVariable("LOGSTREAM_API_TOKEN"),
        transport: LogStreamTransport.Udp,
        udpPort: 8082) // the host defaults to the host of serverUrl; set udpHost to override it
    .CreateLogger();

Each event becomes one datagram, still batched by Serilog before sending. UDP is fire-and-forget: the server never replies, so lost, rejected (stale clock, unknown key, source IP not allowed…) or dropped packets are not reported to the sink β€” check udp.rejected in the server's GET /api/health. Keep clocks NTP-synced: packets must arrive within Β±30 s of the server's time.

Events too large for one datagram (UdpMaxPacketSize, default 8192 bytes, the server's UDP_MAX_PACKET_SIZE) β€” typically ones with long stack traces β€” are posted over HTTP instead, so serverUrl stays required. Set UdpFallbackToHttp = false to drop them (reported to SelfLog).

Call Log.CloseAndFlush() (or dispose the logger) on shutdown so buffered events are sent.

appsettings.json

With Serilog.Settings.Configuration:

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.LogStream" ],
    "MinimumLevel": "Information",
    "WriteTo": [
      {
        "Name": "LogStream",
        "Args": {
          "serverUrl": "https://logs.example.com",
          "appId": "production",
          "apiKey": "billing-api",
          "apiToken": "lss_…",
          "batchSizeLimit": 100,
          "period": "00:00:02"
        }
      }
    ]
  }
}

Keep the secret or token out of source control (user secrets, environment variables such as Serilog__WriteTo__0__Args__apiToken, or a vault).

Arguments

Argument Default Description
serverUrl β€” Base address of the server, e.g. https://logs.example.com
appId β€” Instance or environment identifier (app_id)
appKey null Application slug (app_key); required with apiSecret
apiSecret null Shared write secret (file storage)
apiKey null Client key (MariaDB storage), sent as X-Api-Key
apiToken null Client token (MariaDB storage), sent as X-Api-Token
restrictedToMinimumLevel Verbose Minimum level passed through the sink
batchSizeLimit 100 Events per request (at most 1000)
period 00:00:02 Longest wait before a partial batch is sent
queueLimit 100000 Events buffered in memory; null for no limit
retryTimeLimit 10 minutes How long a failing batch is retried before it is dropped
categoryPropertyName SourceContext Property that becomes the entry category
levelSwitch null Switch to change the minimum level at runtime
formatProvider invariant culture Culture used to render messages
messageHandler null HTTP message handler for the sink's client (e.g. a proxy)
transport Http Http, or Udp for signed, fire-and-forget datagrams
udpHost host of serverUrl Host that receives UDP datagrams
udpPort 8082 UDP port (the server's UDP_PORT)

UdpMaxPacketSize (default 8192) and UdpFallbackToHttp (default true) are set through the options overload below.

Full options

Log.Logger = new LoggerConfiguration()
    .Enrich.FromLogContext()
    .WriteTo.LogStream(
        o =>
        {
            o.ServerUrl = new Uri("https://logs.example.com");
            o.ApiKey = "billing-api";
            o.ApiToken = token;
            o.AppId = builder.Environment.EnvironmentName;
            o.StaticContext["region"] = "eu-west-1";
            o.HttpClient = httpClientFactory.CreateClient("logstream"); // optional
        },
        batching =>
        {
            batching.BatchSizeLimit = 200;
            batching.BufferingTimeLimit = TimeSpan.FromSeconds(1);
            batching.RetryTimeLimit = TimeSpan.FromMinutes(2);
        })
    .CreateLogger();

LogStream is meant for back-end services: don't log to it from browser or mobile front ends, where the credentials would be exposed.


What is sent

LogStream field Taken from
level Verbose, Debug β†’ debug; Information β†’ info; Warning β†’ warning; Error β†’ error; Fatal β†’ critical
category The SourceContext property (the ForContext<T>() logger name), or CategoryPropertyName; general when missing. Truncated to 100 characters
message The rendered message (invariant culture unless formatProvider is set)
message_template The message template text, so LogStream groups every event from the same line (IncludeMessageTemplate)
context StaticContext, then every event property as JSON ({@Object} structures keep their shape and a $type tag), span_id, and exception
context.exception type, message, stack_trace, source and inner_exception (or inner_exceptions for an AggregateException)
trace_id The event's trace ID (Serilog 4 captures Activity.Current); without one, the server generates one per entry
timestamp The event timestamp, in UTC
app_key, app_id, batch_id The options, and a new GUID per request
User-Agent header {entry assembly}/{version} (Serilog.Sinks.LogStream/{version}), or UserAgent

Over UDP each datagram is {"v":1,"key":…,"ts":…,"nonce":…,"sig":…,"log":{…}}: key is apiKey (or appKey), ts the send time in Unix milliseconds, nonce 16 random bytes as hex, and sig the hex HMAC-SHA256(secret, "{key}:{ts}:{nonce}:{log}") over the exact log text. log holds the fields above plus app_id, batch_id (shared by the events of one Serilog batch) and user_agent.


Batching and failures

The sink uses Serilog's built-in batching (BatchingOptions):

Argument Default Description
batchSizeLimit 100 Events per request (at most 1000, the server's limit)
period 2 s Longest wait before a partial batch is sent
queueLimit 100,000 Events kept in memory; newer ones are dropped while full
retryTimeLimit 10 min How long a failing batch is retried before it is dropped

Network errors, timeouts and HTTP 408, 429 and 5xx are retried with back-off. Other rejections (400, 401, 403…) are reported to SelfLog and the batch is dropped, because sending it again would fail the same way. Entries the server rejects one by one (the errors list of a 201/202 response) are reported to SelfLog too.

Over UDP, only a failure to resolve the host (or of the HTTP fallback for oversized events, which is sent first) is retried. Datagrams the OS refuses to send are reported to SelfLog and dropped rather than retried, so an event is never sent twice.

Serilog.Debugging.SelfLog.Enable(Console.Error);

Project Description
logstream-server The ingestion and streaming server
logstream-ui The dashboard
CrispyWaffle.LogStream The LogStream log provider for the CrispyWaffle toolkit

Building

dotnet build
dotnet test
dotnet csharpier check .

Support

If you need help, feel free to open an issue.


Contributing

Contributions are welcome! Fork the repository, create a branch, and open a pull request. Please run dotnet csharpier format . and make sure dotnet test passes before submitting.


Contributors

Thanks to all contributors! πŸ’™

<table> <tbody> <tr> <td align="center"> <a href="https://github.com/guibranco"> <img src="https://avatars.githubusercontent.com/u/3362854?v=4" width="100;" alt="guibranco"/> <br /> <sub><b>Guilherme Branco Stracini</b></sub> </a> </td> </tr> </tbody> </table>

Bots

<table> <tbody> <tr> <td align="center"> <a href="https://github.com/dependabot[bot]"> <img src="https://avatars.githubusercontent.com/in/29110?v=4" width="100;" alt="dependabot[bot]"/> <br /> <sub><b>dependabot[bot]</b></sub> </a> </td> <td align="center"> <a href="https://github.com/github-actions[bot]"> <img src="https://avatars.githubusercontent.com/in/15368?v=4" width="100;" alt="github-actions[bot]"/> <br /> <sub><b>github-actions[bot]</b></sub> </a> </td> <td align="center"> <a href="https://github.com/snyk-bot"> <img src="https://avatars.githubusercontent.com/u/19733683?v=4" width="100;" alt="snyk-bot"/> <br /> <sub><b>Snyk bot</b></sub> </a> </td> </tr> </tbody> </table>


License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.3 0 11/22/2026
1.1.2 90 11/19/2026
1.1.1 104 11/18/2026
1.1.0 103 11/16/2026
1.0.6 95 11/16/2026
1.0.5 123 11/15/2026
1.0.4 87 11/15/2026
1.0.3 93 11/15/2026
1.0.2 85 11/15/2026
1.0.1 91 11/15/2026
1.0.0 92 11/15/2026
0.0.2 123 11/15/2026
0.0.1 137 11/15/2026