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
                    
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.Enrichers.Metrics.Memory" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Serilog.Enrichers.Metrics.Memory" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="Serilog.Enrichers.Metrics.Memory" />
                    
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.Enrichers.Metrics.Memory --version 0.2.0
                    
#r "nuget: Serilog.Enrichers.Metrics.Memory, 0.2.0"
                    
#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.Enrichers.Metrics.Memory@0.2.0
                    
#: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.Enrichers.Metrics.Memory&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=Serilog.Enrichers.Metrics.Memory&version=0.2.0
                    
Install as a Cake Tool

Serilog.Enrichers.Metrics

Build NuGet

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 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. 
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
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