Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ${aspnet-request-contenttype} (ASP.NET Core only) #126

Merged
merged 1 commit into from
Mar 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// ASP.NET content type.
/// </summary>
/// <example>
/// <code lang="NLog Layout Renderer">
/// ${aspnet-request-contenttype}
/// </code>
/// </example>
[LayoutRenderer("aspnet-request-contenttype")]
public class AspNetRequestContentTypeLayoutRenderer : AspNetLayoutRendererBase
{
/// <summary>
/// Renders the specified ASP.NET Application variable and appends it to the specified <see cref="StringBuilder" />.
/// </summary>
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
/// <param name="logEvent">Logging event.</param>
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