Skip to content

Commit

Permalink
Implement review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Burak Akgerman committed Jul 2, 2022
1 parent 5082746 commit 840483f
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
using NLog.LayoutRenderers;
#if ASP_NET_CORE3
using Microsoft.AspNetCore.Connections.Features;
using NLog.Config;
using NLog.LayoutRenderers;
using NLog.Web.Enums;
using NLog.Web.Internal;
using System.Text;

namespace NLog.Web.LayoutRenderers
{
/// <summary>
/// ASP.NET TSL Handshake
/// ASP.NET TLS Handshake
/// </summary>
/// <remarks>
/// ${aspnet-tls-handshake}
/// ${aspnet-tls-handshake:Property=CipherAlgorithm}
/// ${aspnet-tls-handshake:Property=CipherStrength}
/// ${aspnet-tls-handshake:Property=HashAlgorithm}
/// ${aspnet-tls-handshake:Property=HashStrength}
/// ${aspnet-tls-handshake:Property=KeyExchangeAlgorithm}
/// ${aspnet-tls-handshake:Property=KeyExchangeStrength}
/// ${aspnet-tls-handshake:Property=Protocol}
/// </remarks>
[LayoutRenderer("aspnet-tls-handshake")]
public class AspNetTlsHandshakeLayoutRenderer : AspNetLayoutRendererBase
Expand All @@ -17,17 +27,22 @@ public class AspNetTlsHandshakeLayoutRenderer : AspNetLayoutRendererBase
/// Specifies which of the 7 properties of ITlsHandshakeFeature to emit
/// Defaults to the protocol
/// </summary>
[DefaultParameter]
public TlsHandshakeProperty Property { get; set; } = TlsHandshakeProperty.Protocol;

/// <summary>
/// Render TLS Handshake Cipher Algorithm
/// Render TLS Handshake Information
/// </summary>
/// <param name="builder"></param>
/// <param name="logEvent"></param>
protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
{
#if ASP_NET_CORE3
var tlsHandshake = HttpContextAccessor.HttpContext.TryGetTlsHandshake();
var features = HttpContextAccessor.HttpContext.TryGetFeatureCollection();
if(features == null)
{
return;
}
var tlsHandshake = features.Get<ITlsHandshakeFeature>();
if (tlsHandshake == null)
{
return;
Expand Down Expand Up @@ -57,7 +72,8 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
builder.Append(tlsHandshake.Protocol);
break;
}
#endif

}
}
}
#endif

0 comments on commit 840483f

Please sign in to comment.