Soenneker.Serilog.Sinks.R2 11.0.3

Prefix Reserved
dotnet add package Soenneker.Serilog.Sinks.R2 --version 11.0.3
                    
NuGet\Install-Package Soenneker.Serilog.Sinks.R2 -Version 11.0.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="Soenneker.Serilog.Sinks.R2" Version="11.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Serilog.Sinks.R2" Version="11.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Serilog.Sinks.R2" />
                    
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 Soenneker.Serilog.Sinks.R2 --version 11.0.3
                    
#r "nuget: Soenneker.Serilog.Sinks.R2, 11.0.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 Soenneker.Serilog.Sinks.R2@11.0.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=Soenneker.Serilog.Sinks.R2&version=11.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Serilog.Sinks.R2&version=11.0.3
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Serilog.Sinks.R2

A batched Serilog sink for structured logs in Cloudflare R2.

Installation

dotnet add package Soenneker.Serilog.Sinks.R2

Configure the sink

Register the Cloudflare R2 utility and resolve it when the first batch is ready. The following example uses Serilog's hosting integration.

using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Soenneker.Cloudflare.R2.Abstract;
using Soenneker.Cloudflare.R2.Registrars;
using Soenneker.Serilog.Sinks.R2;

builder.Services.AddCloudflareR2UtilAsSingleton();
builder.Services.AddSerilog((services, logger) => logger
    .WriteTo.Console()
    .WriteTo.R2(services.GetRequiredService<ICloudflareR2Util>,
        accountId: "your-cloudflare-account-id",
        bucketName: "application-logs",
        prefix: "production/api"));

Create the destination bucket and supply a Cloudflare API token with object write access through the application's secret provider under Cloudflare:ApiKey. Set Cloudflare:RequestResponseLogging to true to log transport diagnostics. Upload diagnostics go to the other configured sinks so they cannot trigger recursive uploads.

Storage and delivery

Each object contains UTF-8 newline-delimited JSON, for example production/api/2026/11/23/70cc50f8-cd1c-48cb-9a7a-5356a224673e.ndjson. Its UTC date is the date of the first event in that object. Each line contains the original timestamp, level, message template, structured properties and exception when present.

Setting Default Effect
maxObjectBytes 4 MiB Splits a batch on whole-event boundaries. An event larger than the entire limit is counted and skipped.
uploadTimeout 30 seconds Bounds one upload attempt, including reading the acknowledgement.
batchingOptions.BatchSizeLimit 1,000 events Maximum events delivered to the sink together.
batchingOptions.BufferingTimeLimit 2 seconds Maximum normal batching delay.
batchingOptions.QueueLimit 100,000 events Bounds the in-process Serilog queue by event count.
batchingOptions.RetryTimeLimit 10 minutes Controls how long Serilog retries failed batches.

A successful write requires both an HTTP success status and a Cloudflare acknowledgement. After a timeout or lost response, the sink retries the exact bytes at the same key. Objects already acknowledged in a split batch are skipped on retry. Concurrent application instances generate independent keys.

Buffering is in memory. Process termination, queue overflow, an exhausted retry window or a failed shutdown flush can lose events. Dispose the logger before disposing its Cloudflare client provider. Use await Log.CloseAndFlushAsync() for the static logger. Applications that require a persistent audit record should also write to a durable destination.

Monitor delivery

Subscribe to the .NET meter Soenneker.Serilog.Sinks.R2 with a metrics listener or an OpenTelemetry meter provider. Counters have no per-object or tenant tags.

Counter Meaning
r2.objects.uploaded Objects acknowledged by Cloudflare
r2.bytes.uploaded NDJSON bytes in acknowledged objects
r2.upload.failures Failed attempts, including timeouts and invalid acknowledgements
r2.events.oversized Individual events skipped because they exceeded the object limit

Enable Serilog.Debugging.SelfLog.Enable(Console.Error) for Serilog delivery failures and oversized-event diagnostics. Keep the diagnostic writer independent of the logger. Alert on sustained upload failures and oversized events. A failure count includes retried attempts and cannot be used as a count of lost events.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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
11.0.3 0 11/23/2026
11.0.1 0 11/23/2026

Accept upload deadline cancellation during authentication