Skip to content

Commit

Permalink
AspNetRequestPostedBodyLayoutRenderer - Single lookup using TryGetVal…
Browse files Browse the repository at this point in the history
…ue (#848)
  • Loading branch information
snakefoot authored Aug 9, 2022
1 parent 9b5b7db commit b19cfa1
Showing 1 changed file with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,23 @@ public class AspNetRequestPostedBodyLayoutRenderer : AspNetLayoutRendererBase
/// <inheritdoc/>
protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
{
var httpContext = HttpContextAccessor.HttpContext;
if (httpContext == null)
{
return;
}

var items = httpContext.Items;
if (items == null)
{
return;
}

if (httpContext.Items.Count == 0)
var items = HttpContextAccessor.HttpContext?.Items;
if (items == null || items.Count == 0)
{
return;
}

#if !ASP_NET_CORE
if (!items.Contains(NLogPostedRequestBodyKey))
if (items.Contains(NLogPostedRequestBodyKey))
{
return;
builder.Append(items[NLogPostedRequestBodyKey] as string);
}
#else
if (!items.ContainsKey(NLogPostedRequestBodyKey))
if (items.TryGetValue(NLogPostedRequestBodyKey, out var value))
{
return;
builder.Append(value as string);
}
#endif

builder.Append(items[NLogPostedRequestBodyKey] as string);
}
}
}

0 comments on commit b19cfa1

Please sign in to comment.