NLog / NLog.Web

NLog integration for ASP.NET & ASP.NET Core 2-8
https://nlog-project.org
BSD 3-Clause "New" or "Revised" License
320 stars 166 forks source link

Add support for Custom Claim management in AspNetUserClaimLayoutRenderer #1016

Closed Fabman08 closed 11 months ago

Fabman08 commented 11 months ago

New Feature

Manage Custom Claim value in AspNetUserClaimLayoutRenderer

Motivation for New Feature

This feature allows to retrieve information about the current user logged also in custom claims

Proposed Changes

Added new prefix CustomClaim. in ClaimType

Description

Now the parameter ClaimType checks only if the value specified is ClaimTypes. or ClaimType. Adding the new prefix CustomClaim. in ClaimType you can specify your custom claim full path with the below pattern

aspnet-user-claim:CustomClaim.scheme.host/mypath

Ex.

"targets": {
   "myTarget": {
      "type": "Console",
      "layout": "${date}|${level}|${aspnet-user-claim:CustomClaim.http.schemas.mycompany.com/identity/claims/myclaim}"
   }
}

NLog version: 5.2.7

NLog.Web / NLog.Web.AspNetCore version: 5.3.7

NLog.Extensions.Logging version: 5.3.7

Platform: .Net 3.5 / .Net 4.6 / .NET Core 3.1 / .NET 6.0

Pull Request Reference #1017

Fabman08 commented 11 months ago

Escaping colon with double backslash solve the problem