Soenneker.Utils.ReusableStringWriter
4.0.26
Prefix Reserved
dotnet add package Soenneker.Utils.ReusableStringWriter --version 4.0.26
NuGet\Install-Package Soenneker.Utils.ReusableStringWriter -Version 4.0.26
<PackageReference Include="Soenneker.Utils.ReusableStringWriter" Version="4.0.26" />
<PackageVersion Include="Soenneker.Utils.ReusableStringWriter" Version="4.0.26" />
<PackageReference Include="Soenneker.Utils.ReusableStringWriter" />
paket add Soenneker.Utils.ReusableStringWriter --version 4.0.26
#r "nuget: Soenneker.Utils.ReusableStringWriter, 4.0.26"
#:package Soenneker.Utils.ReusableStringWriter@4.0.26
#addin nuget:?package=Soenneker.Utils.ReusableStringWriter&version=4.0.26
#tool nuget:?package=Soenneker.Utils.ReusableStringWriter&version=4.0.26
Soenneker.Utils.ReusableStringWriter
A high-performance, reusable StringWriter that avoids unnecessary allocations by clearing and reusing its internal StringBuilder instance.
Installation
dotnet add package Soenneker.Utils.ReusableStringWriter
Quick start
using Soenneker.Utils.ReusableStringWriter;
Create one writer for a bounded synchronous scope and reset it between payloads:
using var writer = new ReusableStringWriter();
foreach (Order order in orders)
{
writer.Write("Order: ");
writer.Write(order.Id);
string text = writer.Finish();
await destination.WriteAsync(text, cancellationToken);
writer.Reset();
}
Finish calls StringBuilder.ToString(): it allocates an independent string and leaves all
characters in the writer. Call Reset explicitly before writing the next value. Reset changes the
logical length to zero but retains the builder's capacity, which is where the allocation savings
come from.
The writer starts with capacity 256 and grows as needed. A single unusually large payload can therefore leave a large retained buffer for the rest of that writer's lifetime. Choose a bounded reuse lifetime when payload sizes vary significantly.
Lifecycle and inherited behavior
- Reuse the writer before disposing it. Dispose once when the whole reuse scope ends; disposal is not a reset operation.
- The type is not thread-safe. Do not write, finish, or reset it concurrently.
Finishcan be called repeatedly, but every call creates another string.Resetdoes not securely erase the underlying character array. Do not use the writer as secure storage for secrets.Encoding,NewLine, format-provider behavior, and the synchronous/asyncTextWriterAPIs come fromStringWriter. In particular, consumers such as XML serializers can observeStringWriter.Encodingwhen emitting an encoding declaration.
There is no dependency-injection registration; instantiate the writer where its ownership and reuse boundary are clear.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Soenneker.Utils.ReusableStringWriter:
| Package | Downloads |
|---|---|
|
Serilog.Sinks.XUnit.Injectable
The injectable, xUnit test output sink for Serilog |
|
|
Soenneker.Serilog.Sinks.TUnit
A Serilog sink for logging within TUnit |
|
|
Soenneker.Serilog.Sinks.Browser.Blazor
A Serilog sink for logging within the Blazor client-side environment |
|
|
Soenneker.Serilog.Sinks.Cache
A Serilog sink cache that allows for storing, retrieving, and removing log messages |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.26 | 13,830 | 8/30/2026 |
| 4.0.25 | 6,577 | 8/29/2026 |
| 4.0.24 | 179,829 | 7/27/2026 |
| 4.0.23 | 81,092 | 7/16/2026 |
| 4.0.22 | 112,136 | 6/18/2026 |
| 4.0.20 | 108,555 | 6/5/2026 |
| 4.0.19 | 148,002 | 4/23/2026 |
| 4.0.18 | 141,099 | 3/12/2026 |
| 4.0.14 | 33,972 | 3/10/2026 |
| 4.0.13 | 20,209 | 3/9/2026 |
| 4.0.12 | 339 | 3/9/2026 |
| 4.0.11 | 40,677 | 3/4/2026 |
| 4.0.10 | 2,526 | 3/4/2026 |
| 4.0.9 | 174,455 | 1/2/2026 |
| 4.0.8 | 71,967 | 11/20/2025 |
| 4.0.7 | 34,955 | 11/6/2025 |
| 4.0.6 | 19,500 | 10/29/2025 |
| 3.0.5 | 96,144 | 9/3/2025 |
| 3.0.4 | 26,119 | 8/11/2025 |
| 3.0.3 | 25,769 | 7/23/2025 |
Document reusable writer lifecycle