From ac175deea29a0f84d9c843a93839bde33acbfae4 Mon Sep 17 00:00:00 2001
From: Julian Verdurmen <304NotModified@users.noreply.github.com>
Date: Fri, 31 Mar 2017 00:01:13 +0200
Subject: [PATCH] Add ${aspnet-request-contenttype} (ASP.NET Core only)
---
.../AspNetRequestContentTypeLayoutRenderer.cs | 39 +++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 NLog.Web.AspNetCore/LayoutRenderers/AspNetRequestContentTypeLayoutRenderer.cs
diff --git a/NLog.Web.AspNetCore/LayoutRenderers/AspNetRequestContentTypeLayoutRenderer.cs b/NLog.Web.AspNetCore/LayoutRenderers/AspNetRequestContentTypeLayoutRenderer.cs
new file mode 100644
index 00000000..3597384a
--- /dev/null
+++ b/NLog.Web.AspNetCore/LayoutRenderers/AspNetRequestContentTypeLayoutRenderer.cs
@@ -0,0 +1,39 @@
+#if NETSTANDARD_1plus
+using NLog.LayoutRenderers;
+using System.Text;
+
+using Microsoft.AspNetCore.Routing;
+
+using NLog.Web.Internal;
+
+namespace NLog.Web.LayoutRenderers
+{
+ ///
+ /// ASP.NET content type.
+ ///
+ ///
+ ///
+ /// ${aspnet-request-contenttype}
+ ///
+ ///
+ [LayoutRenderer("aspnet-request-contenttype")]
+ public class AspNetRequestContentTypeLayoutRenderer : AspNetLayoutRendererBase
+ {
+ ///
+ /// Renders the specified ASP.NET Application variable and appends it to the specified .
+ ///
+ /// The to append the rendered data to.
+ /// Logging event.
+ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
+ {
+ var request = HttpContextAccessor?.HttpContext?.TryGetRequest();
+
+ var contentType = request?.ContentType;
+
+ if (!string.IsNullOrEmpty(contentType))
+ builder.Append(contentType);
+
+ }
+ }
+}
+#endif
\ No newline at end of file