Serilog.Enrichers.AzureClaims 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Serilog.Enrichers.AzureClaims --version 0.1.0                
NuGet\Install-Package Serilog.Enrichers.AzureClaims -Version 0.1.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.AzureClaims" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Serilog.Enrichers.AzureClaims --version 0.1.0                
#r "nuget: Serilog.Enrichers.AzureClaims, 0.1.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.
// Install Serilog.Enrichers.AzureClaims as a Cake Addin
#addin nuget:?package=Serilog.Enrichers.AzureClaims&version=0.1.0

// Install Serilog.Enrichers.AzureClaims as a Cake Tool
#tool nuget:?package=Serilog.Enrichers.AzureClaims&version=0.1.0                

Serilog.Enrichers.AzureClaims

Build_and_Test

Enriches Serilog events with information from the ClaimsPrincipal.

Install the Serilog.Enrichers.AzureClaims NuGet package

Install-Package Serilog.Enrichers.AzureClaims

Then, apply the enricher to your LoggerConfiguration:

Log.Logger = new LoggerConfiguration()
    .Enrich.WithUPN()
    .Enrich.WithDisplayName()
    .Enrich.WithTID()
    .Enrich.WithOID()
    .Enrich.WithAppId()
    // ...other configuration...
    .CreateLogger();

Included enrichers

The package includes:

  • WithUPN() - adds UserPrincipalName based on the ClaimType http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn
  • WithDisplayName() - adds DisplayName based on the ClaimType http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name or name or preferred_username
  • WithTID() - adds TenantId based on the ClaimType http://schemas.microsoft.com/identity/claims/tenantid or tid
  • WithOID() - adds ObjectIdentifier based on the ClaimType http://schemas.microsoft.com/identity/claims/objectidentifier or oid
  • WithAppId - adds AppId based on the CLaimType appid or azp

Installing into an ASP.NET Core Web Application

You need to register the IHttpContextAccessor singleton so the enrichers have access to the requests HttpContext to extract the data. This is what your Program class should contain in order for this enricher to work as expected:

// ...
using Serilog;

var builder = WebApplication.CreateBuilder(args);

builder.Logging.AddSerilog(new LoggerConfiguration()
    .Enrich.WithUPN()
    .Enrich.WithDisplayName()
    .Enrich.WithTID()
    .Enrich.WithOID()
    .CreateLogger());

// ...
builder.Services.AddHttpContextAccessor();
// ...

var app = builder.Build();
app.UseSerilogRequestLogging();
// ...

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Serilog.Enrichers.AzureClaims:

Package Downloads
Intility.Logging.AspNetCore

This package enables common logging infrastructure to any aspnet or dotnet project using generic host mechanism. Additional logging capabilities are available through the extension packages Intility.Extensions.Logging.*

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 288 11/22/2024
1.1.1-rc.2 53 11/22/2024
1.1.1-rc.1 58 11/22/2024
1.1.1-rc.0 56 11/22/2024
1.1.0 89 11/21/2024
1.0.3 10,187 1/10/2024
1.0.2 33,816 11/16/2023
1.0.1 7,625 7/11/2023
1.0.1-tags-v1-0-1-rc--0001 152 7/11/2023
1.0.0 184 7/11/2023
0.1.2 298 6/28/2023
0.1.1 630 6/27/2023
0.1.0 152 6/27/2023