Coder Social home page Coder Social logo

intility / serilog-enrichers-azureclaims Goto Github PK

View Code? Open in Web Editor NEW
2.0 6.0 0.0 103 KB

A Serilog enricher that enriches the log event with claims from Azure v1 and v2 accesstokens.

License: MIT License

C# 89.83% Batchfile 0.35% PowerShell 5.41% Shell 4.41%
accesstoken serilog serilog-enricher

serilog-enrichers-azureclaims's Introduction

Serilog.Enrichers.AzureClaims

Enriches Serilog events with information from the ClaimsPrincipal.

Build_and_Test Publish codecov

Nuget Nuget

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.WithTenantId()
    .Enrich.WithObjectId()
    .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
  • WithTenantId() - adds TenantId based on the ClaimType http://schemas.microsoft.com/identity/claims/tenantid or tid
  • WithObjectId() - adds ObjectId 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.WithTenantId()
    .Enrich.WithObjectId()
    .Enrich.WithAppId()
    .CreateLogger());

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

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

serilog-enrichers-azureclaims's People

Contributors

loekensgard avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.