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

Fixing missing name for ${aspnet-request-cookie} #100

Merged
merged 1 commit into from
Feb 10, 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
Expand Up @@ -27,7 +27,7 @@ namespace NLog.Web.LayoutRenderers
[LayoutRenderer("aspnet-request-cookie")]
public class AspNetRequestCookieLayoutRenderer : AspNetLayoutRendererBase
{
private const string flatCookiesSeparator = "=";
private const string cookiesNameSeparator = "=";
private const string flatItemSeperator = ",";

/// <summary>
Expand Down Expand Up @@ -60,7 +60,8 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
bool firstItem = true;
foreach (var cookieName in this.CookieNames)
{
this.SerializeCookie(httpRequest.Cookies[cookieName], builder, firstItem);
var cookieValue = httpRequest.Cookies[cookieName];
this.SerializeCookie(cookieName, cookieValue, builder, firstItem);
firstItem = false;
}
}
Expand All @@ -70,22 +71,23 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
/// <summary>
/// To Serialize the HttpCookie based on the configured output format.
/// </summary>
/// <param name="cookieName">Name of the cookie</param>
/// <param name="cookie">The current cookie item.</param>
/// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
/// <param name="firstItem">Whether it is first item.</param>
private void SerializeCookie(HttpCookie cookie, StringBuilder builder, bool firstItem)
private void SerializeCookie(string cookieName, HttpCookie cookie, StringBuilder builder, bool firstItem)
{
if (cookie != null)
{
var cookieRaw = $"{cookie.Name}{flatCookiesSeparator}{cookie.Value}";

SerializeCookie(cookieRaw, builder, firstItem);
this.SerializeCookie(cookieName, cookie.Value, builder, firstItem);
}
}

#endif
private void SerializeCookie(string cookieRaw, StringBuilder builder, bool firstItem)
private void SerializeCookie(string cookieName, string cookieValue, StringBuilder builder, bool firstItem)
{
var cookieRaw = $"{cookieName}{cookiesNameSeparator}{cookieValue}";

switch (this.OutputFormat)
{
case AspNetRequestLayoutOutputFormat.Flat:
Expand Down