Voyager.Serilog.Settings.Configuration 1.1.5

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

Voyager.Serilog.Settings.Configuration

Guide

This project provides helper methods for registering Serilog with custom identity providers in an ASP.NET Core application. It includes methods to clean existing logging providers and register Serilog with or without an identity provider.

Prerequisites

  • .NET 8.0
  • Visual Studio 2022

NuGet Packages

Ensure the following NuGet packages are installed in your project:

  • Serilog.AspNetCore
  • Serilog.Expressions
  • Serilog.Enrichers.Environment
  • Voyager.Serilog.Sinks.FastEMail
  • Voyager.Serilog.Settings.Configuration

Serilog Configuration

This is a example serilog configuration using BackendSerilogFormatter to log formated messages to console

{
  "Serilog": {
    "Using": [
      "Serilog.Enrichers.Environment",
      "Serilog.Sinks.Console",
      "Serilog",
      "Serilog.Expressions"
    ],
    "Filter": [
      {
        "Name": "ByExcluding",
        "Args": {
          "expression": "@Message like'%Executed DbCommand %'"
        }
      }
    ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "System": "Warning"
      }
    },
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "formatter": "Voyager.Serilog.Settings.Configuration.Formatters.BackendSerilogFormatter, Voyager.Serilog.Settings.Configuration"
        }
      },
      {
        "Name": "FastEmail",
        "Args": {
          "ConnectionInfo": {
            "FromEmail": "{use application name here}@voyager.pl",
            "ToEmail": "{email adress of the person/group who will recive the email notification when an error occurs}",
            "EmailSubject": "[{Level}],<{MachineName}> {use application name here}",
            "IsBodyHtml": false,
            "mailServer": "mgw.voyager.pl"
          },
          "RestrictedToMinimumLevel": "Error",
          "OutputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u4}] Maszyna:{MachineName} ASPNETCORE_ENVIRONMENT:%ASPNETCORE_ENVIRONMENT% {NewLine:l}{Message}{NewLine:l}{Exception}{NewLine:l}{Properties}"
        }
      }
    ],
    "Enrich": [ "FromLogContext", "WithCaller" ],
    "Properties": {
      "Application": "{use application name here}"
    }
  }
}

Registration Example:

  • .NET 8.0 registartion with WebApplicationBuilder:
public static WebApplicationBuilder RegisterSerilog(this WebApplicationBuilder builder)
{
	builder.Host.UseSerilog((context, services, configuration) =>
	{
		configuration
			.ReadFrom.Configuration(context.Configuration);
	}, true);

	return builder;
}

Identity Provider Usage

To add user claims into logged data you first have to add the fallowing NuGet packages:

  • Voyager.RestAPI.Interface
  • Voyager.Enricher.Identity

Also the registration will change to:

  • For .NET 8.0 with Identity
public static WebApplicationBuilder RegisterSerilog(this WebApplicationBuilder builder)
{
	builder.Host.UseSerilog((context, services, configuration) =>
	{
		configuration
			.ReadFrom.Configuration(context.Configuration)
			.Enrich.WithIdentityEnricher(() => services.GetService<IdentityProvider>()!);
	}, true);

	return builder;
}

Console Outputs

  • WorkerLogOutput which returns the log with data:
class WorkerLogOutput
{
	public string Timestamp { get; set; } = string.Empty;
	public string Level { get; set; } = string.Empty;
	public string Message { get; set; } = string.Empty;
	public string? Scope { get; set; } = string.Empty;

	public IReadOnlyDictionary<string, string> Properties { get; set; } = new Dictionary<string, string>();
	public SerializableException? Exception { get; set; } = new SerializableException();
}
  • BackendLogOutput which extends the WorkerLogOutput class for caller informations
class BackendLogOutput : WorkerLogOutput
{
	public string? Caller { get; set; } = string.Empty;
}

To use either of thoes two console log options you have to change the formatter value in serilog options:

"formatter": "Voyager.Serilog.Settings.Configuration.Formatters.WorkerSerilogFormatter, Voyager.Serilog.Settings.Configuration"

or

"formatter": "Voyager.Serilog.Settings.Configuration.Formatters.BackendSerilogFormatter, Voyager.Serilog.Settings.Configuration"
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. 
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.1.5 187 3/20/2025
1.1.4 138 3/19/2025
1.1.3 131 3/19/2025
1.1.2 131 3/19/2025
1.1.1 131 3/19/2025
1.1.0 134 3/19/2025
1.0.4 188 3/12/2025
1.0.3 142 3/12/2025
1.0.2 133 3/12/2025
1.0.1 148 3/11/2025
1.0.0 145 3/11/2025