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
<PackageReference Include="Serilog.Sinks.LogStream" Version="1.1.3" />
<PackageVersion Include="Serilog.Sinks.LogStream" Version="1.1.3" />
<PackageReference Include="Serilog.Sinks.LogStream" />
paket add Serilog.Sinks.LogStream --version 1.1.3
#r "nuget: Serilog.Sinks.LogStream, 1.1.3"
#:package Serilog.Sinks.LogStream@1.1.3
#addin nuget:?package=Serilog.Sinks.LogStream&version=1.1.3
#tool nuget:?package=Serilog.Sinks.LogStream&version=1.1.3
Serilog.Sinks.LogStream
π‘πͺ΅ A Serilog sink that writes events to a LogStream server.

Documentation: GitHub Pages
Table of content
- Features: What the sink does.
- CI/CD: Current project status in the build pipeline (GitHub Actions).
- Code Quality: Metrics about code quality.
- .NET support: Supported target frameworks.
- Installation: How to install/download the package.
- Usage: How to set up, configure and use the sink.
- What is sent: How Serilog events map to LogStream entries.
- Batching and failures: Buffering, retries and diagnostics.
- Related projects: The rest of the LogStream ecosystem.
- Building: How to build and test locally.
- Support: How to get support.
- Contributing: How to contribute.
Features
- Batched delivery β events are sent in batches to
POST /api/logsusing 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-appX-Api-Key/X-Api-Token). - Resilient β transient failures (network errors, timeouts, 408, 429, 5xx) are retried with back-off;
permanent rejections are reported to
SelfLogand dropped. - Configurable from code or
appsettings.jsonβ works with Serilog.Settings.Configuration. - Trace-aware β Serilog 4 captures
Activity.Current, so thetrace_idandspan_idflow to LogStream.
CI/CD
| Build and tests | Release | Last commit |
|---|---|---|
Code Quality
.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
Download the latest .nupkg from the Releases page.
NuGet package manager
| Package | Version | Downloads |
|---|---|---|
| Serilog.Sinks.LogStream |
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);
Related projects
| 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 | Versions 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. |
-
.NETStandard 2.0
- Serilog (>= 4.4.0)
- System.Text.Json (>= 11.0.0)
-
net10.0
- Serilog (>= 4.4.0)
-
net8.0
- Serilog (>= 4.4.0)
-
net9.0
- Serilog (>= 4.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.