Serilog.ConfigHelper 1.3.1

dotnet add package Serilog.ConfigHelper --version 1.3.1
NuGet\Install-Package Serilog.ConfigHelper -Version 1.3.1
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.ConfigHelper" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.ConfigHelper --version 1.3.1
#r "nuget: Serilog.ConfigHelper, 1.3.1"
#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.
// Install Serilog.ConfigHelper as a Cake Addin
#addin nuget:?package=Serilog.ConfigHelper&version=1.3.1

// Install Serilog.ConfigHelper as a Cake Tool
#tool nuget:?package=Serilog.ConfigHelper&version=1.3.1

Serilog.ConfigHelper Library

Provides various built-in enrichers for Serilog and a TemplateBuilder to help you build Serilog templates easily.

Installation

You can install the package via NuGet:

Install-Package Serilog.ConfigHelper

Usage

TemplateBuilder

Easily build Serilog templates with the TemplateBuilder. The TemplateBuilder provides methods to add the following elements to the template:

  • Timestamp
  • Level
  • Message
  • Exception
  • Property
  • NewLine

The order which the Add methods used is the order which the elements will appear in the template.

Creating default template builder

var template = new TemplateBuilder()
    .AddTimestamp()
    .AddLevel()
    .AddMessage()
    .AddException()
    .Build();

Creating template with properties

var template = new TemplateBuilder()
    .AddTimestamp()
    .AddLevel()
    .AddProperty("ThreadId") // Add property with name
    .AddProperty("MachineName",true) // Add property with name inside square brackets
    .AddMessage()
    .AddException()
    .Build();

Enrichers

Built-in enrichers for Serilog. You can change the default PropertyName for each enricher in constructor.

Example usage of enrichers
var logger = new LoggerConfiguration()
    .Enrich.With(new ThreadIdEnricher())
    .Enrich.With(new TimeZoneEnricher())
    .Enrich.With(new ClaimEnricher("ClaimName"))
    .Enrich.With(new HttpRequestUserIdentityNameEnricher())
    .Enrich.With(new HttpRequestAllHeadersEnricher())//Property name will be like this: "Header:HeaderName"
    .CreateLogger();
Common Enrichers

Enriches log events with device or environment information.

Following enrichers are available:

  • OSVersionEnricher
    • Adds the OS version to the log event properties.
  • DiskUUIDEnricher
    • Adds the disk UUID to the log event properties.
  • ThreadIdEnricher
    • Adds the current thread id to the log event properties.
  • TimeZoneEnricher
    • Adds the current time zone to the log event properties.
  • HostIpAddressEnricher
    • Adds the host ip address to the log event properties.
  • EnvironmentVariableEnricher
    • Adds the environment variable to the log event properties.
  • MacAddressEnricher
    • Adds the mac address to the log event properties.
  • MachineNameEnricher
    • Adds the machine name to the log event properties.
  • MachineGuidEnricher
    • Adds the machine guid to the log event properties.
  • StackTraceEnricher (For debugging purposes)
    • Adds the stack trace to the log event properties. This is a heavy task and not performant. This should not be used in production.
AspNetCore HttpRequest Enrichers

Enriches log events with information from the current HttpContext. You must add HttpContextAccessor to the DI container.

Following enrichers are available:

  • HttpRequestClaimEnricher
    • Adds the specified claim from current HttpContext to the log event properties.
  • HttpRequestUserIdentityNameEnricher
    • Adds the user identity name from current HttpContext to the log event properties.
  • HttpRequestAllHeadersEnricher
    • Adds all headers from current HttpContext.Request to the log event properties.
  • HttpRequestHeaderEnricher
    • Adds the specified header from current HttpContext.Request to the log event properties.
  • HttpRequestIdEnricher
    • Adds the request id from current HttpContext.Request to the log event properties.
  • HttpRequestMethodEnricher
    • Adds the request method from current HttpContext.Request to the log event properties.
  • HttpRequestPathEnricher
    • Adds the request path from current HttpContext.Request to the log event properties.
  • HttpRequestProtocolEnricher
    • Adds the request protocol from current HttpContext.Request to the log event properties.
  • HttpRequestQueryStringEnricher
    • Adds the request query string from current HttpContext.Request to the log event properties.
  • HttpRequestSchemeEnricher
    • Adds the request scheme from current HttpContext.Request to the log event properties.
  • HttpRequestStatusCodeEnricher
    • Adds the request status code from current HttpContext.Response to the log event properties.
  • HttpRequestTraceIdentifierEnricher
    • Adds the request trace identifier from current HttpContext.Request to the log event properties.
  • HttpRequestUserAgentEnricher
    • Adds the request user agent from current HttpContext.Request to the log event properties.
  • HttpRequestRolesEnricher
    • Adds the request roles from current HttpContext.User to the log event properties.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 was computed.  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. 
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
1.3.1 476 7/10/2023
1.3.0 152 6/28/2023