Skip to content

Commit

Permalink
AspNetUserClaimLayoutRenderer - Now supported for NLog.Web with NET46 (
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot authored Jun 6, 2022
1 parent 0b1f2a8 commit 3c5e983
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
#if ASP_NET_CORE || NET46_OR_GREATER

using System;
using System.Reflection;
using System.Security.Claims;
using System.Text;
Expand Down Expand Up @@ -60,10 +62,14 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
}

var claimsIdentity = claimsPrincipel.Identity as ClaimsIdentity; // Prioritize primary identity
var claim = claimsIdentity?.FindFirst(ClaimType) ?? claimsPrincipel.FindFirst(ClaimType);
var claim = claimsIdentity?.FindFirst(ClaimType)
#if ASP_NET_CORE
?? claimsPrincipel.FindFirst(ClaimType)
#endif
;
if (claim != null)
{
builder.Append(claim.Value);
builder.Append(claim?.Value);
}
}
catch (ObjectDisposedException ex)
Expand All @@ -73,3 +79,5 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Security.Principal;
#if ASP_NET_CORE || NET46_OR_GREATER

using System.Security.Principal;
#if ASP_NET_CORE
using Microsoft.Extensions.Primitives;
using HttpContextBase = Microsoft.AspNetCore.Http.HttpContext;
#endif
using NLog.Web.LayoutRenderers;
using NSubstitute;
using Xunit;
Expand Down Expand Up @@ -64,3 +68,5 @@ public void UserClaimTypeNameRendersValue()
}
}
}

#endif

0 comments on commit 3c5e983

Please sign in to comment.