Skip to content

Commit

Permalink
Merge pull request #142 from NLog/AspNetUserIdentityLayoutRenderer_Ob…
Browse files Browse the repository at this point in the history
…jectDisposedException

ignore ObjectDisposedException in aspnet-user renderers
  • Loading branch information
304NotModified authored May 13, 2017
2 parents 68dde7a + 5d81e67 commit 836e3e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Text;
#if !NETSTANDARD_1plus
using System.Web;
Expand All @@ -20,14 +21,21 @@ public class AspNetUserAuthTypeLayoutRenderer : AspNetLayoutRendererBase
/// <param name="logEvent">Logging event.</param>
protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
{
var context = HttpContextAccessor.HttpContext;
try
{
var context = HttpContextAccessor.HttpContext;

if (context.User?.Identity?.IsAuthenticated == null)
{
return;
}

if (context.User?.Identity?.IsAuthenticated == null)
builder.Append(context.User.Identity.AuthenticationType);
}
catch (ObjectDisposedException)
{
return;
//ignore ObjectDisposedException, see https://github.com/NLog/NLog.Web/issues/83
}

builder.Append(context.User.Identity.AuthenticationType);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Text;
#if !NETSTANDARD_1plus
using System.Web;
Expand All @@ -20,14 +21,21 @@ public class AspNetUserIdentityLayoutRenderer : AspNetLayoutRendererBase
/// <param name="logEvent">Logging event.</param>
protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
{
var context = HttpContextAccessor.HttpContext;
try
{
var context = HttpContextAccessor.HttpContext;

if (context.User?.Identity == null)
{
return;
}

if (context.User?.Identity == null)
builder.Append(context.User.Identity.Name);
}
catch (ObjectDisposedException)
{
return;
//ignore ObjectDisposedException, see https://github.com/NLog/NLog.Web/issues/83
}

builder.Append(context.User.Identity.Name);
}
}
}

0 comments on commit 836e3e4

Please sign in to comment.