Serilog.Enrichers.Metrics.Memory
0.2.0
dotnet add package Serilog.Enrichers.Metrics.Memory --version 0.2.0
NuGet\Install-Package Serilog.Enrichers.Metrics.Memory -Version 0.2.0
<PackageReference Include="Serilog.Enrichers.Metrics.Memory" Version="0.2.0" />
<PackageVersion Include="Serilog.Enrichers.Metrics.Memory" Version="0.2.0" />
<PackageReference Include="Serilog.Enrichers.Metrics.Memory" />
paket add Serilog.Enrichers.Metrics.Memory --version 0.2.0
#r "nuget: Serilog.Enrichers.Metrics.Memory, 0.2.0"
#:package Serilog.Enrichers.Metrics.Memory@0.2.0
#addin nuget:?package=Serilog.Enrichers.Metrics.Memory&version=0.2.0
#tool nuget:?package=Serilog.Enrichers.Metrics.Memory&version=0.2.0
Serilog.Enrichers.Metrics
Overview
This repository provides Serilog enrichers for monitoring key runtime metrics of the current process. These enrichers are extremely helpful when writing applications where low memory consumption, IO tracking, or elapsed time measurement is critical.
- Serilog.Enrichers.Metrics.IO: Adds metrics for IO read/write operations (
IoReadBytes,IoWriteBytes). - Serilog.Enrichers.Metrics.Memory: Adds metrics for memory usage by the current process (
WorkingSetBytes,ManagedMemoryBytes). - Serilog.Enrichers.Metrics.Stopwatch: Adds a running stopwatch value (
Stopwatch) to each log event, formatted as a time span.
Features
- Track memory usage in real time.
- Monitor IO throughput (read/write bytes).
- Measure elapsed application time with a running stopwatch.
- Simple integration with Serilog.
Installation
Install the desired package(s) from NuGet:
# For IO metrics
dotnet add package Serilog.Enrichers.Metrics.IO
# For memory metrics
dotnet add package Serilog.Enrichers.Metrics.Memory
# For stopwatch elapsed time
dotnet add package Serilog.Enrichers.Metrics.Stopwatch
Usage
Add the enrichers to your Serilog configuration in code:
using Serilog;
var logger = new LoggerConfiguration()
.Enrich.WithIoMetrics()
.Enrich.WithMemoryMetrics()
.Enrich.WithStopwatch() // default format is @"hh\:mm\:ss"
.WriteTo.Console(
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u4}] {Message} | " +
"Read {IoReadBytes:N0} | Write {IoWriteBytes:N0} | " +
"WorkingSet {WorkingSetBytes:N0} | Managed {ManagedMemoryBytes:N0} | " +
"Elapsed {Stopwatch} | {Properties:j}{NewLine}{Exception}")
.CreateLogger();
Custom Stopwatch Format
The Stopwatch enricher accepts an optional format parameter (default: @"hh\:mm\:ss") to control how the elapsed time is rendered.
.Enrich.WithStopwatch(@"hh\:mm\:ss\.fff") // include milliseconds
Example: appsettings.json
You can also configure the enrichers using appsettings.json:
{
"Serilog": {
"Using": [
"Serilog.Enrichers.Metrics.IO",
"Serilog.Enrichers.Metrics.Memory",
"Serilog.Enrichers.Metrics.Stopwatch"
],
"Enrich": [
"WithIoMetrics",
"WithMemoryMetrics",
"WithStopwatch"
],
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u4}] {Message} | " +
"Read {IoReadBytes:N0} | Write {IoWriteBytes:N0} | " +
"WorkingSet {WorkingSetBytes:N0} | Managed {ManagedMemoryBytes:N0} | " +
"Elapsed {Stopwatch} | {Properties:j}{NewLine}{Exception}"
}
}
]
}
}
Created from JandaBox | Icon created by Freepik - Flaticon
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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 was computed. 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. |
-
net8.0
- Serilog (>= 4.3.0)
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 |
|---|---|---|
| 0.2.0 | 356 | 9/28/2025 |
| 0.1.1-stopwatch-enricher.3 | 132 | 9/28/2025 |
| 0.1.1-stopwatch-enricher.1 | 131 | 9/28/2025 |
| 0.1.1-main.1 | 126 | 9/28/2025 |
| 0.1.0 | 183 | 9/28/2025 |
| 0.1.0-memory-enricher.8 | 130 | 9/28/2025 |
| 0.1.0-main.4 | 134 | 9/28/2025 |