I've got a situation where if dnx is restarted for any reason (and thus sessions invalidated) any logging that is performed that has a layout that includes aspnet-session causes a stack overflow. I assume that somewhere there is some code that is trying to log the fact that the session has expired and so given that nlog is then trying to access the session again, we are getting a stack overflow.
Is there any solution to this? We would like to log some information from the session but we obviously cannot have the server crash just from someone accessing the server with an expired session.
Microsoft.AspNet.Session.dll!Microsoft.AspNet.Session.DistributedSession.LoadAsync() Unknown
mscorlib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Microsoft.AspNet.Session.DistributedSession.<LoadAsync>d__19>(ref Microsoft.AspNet.Session.DistributedSession.<LoadAsync>d__19 stateMachine) Unknown
Microsoft.AspNet.Session.dll!Microsoft.AspNet.Session.DistributedSession.LoadAsync() Unknown
Microsoft.AspNet.Session.dll!Microsoft.AspNet.Session.DistributedSession.Load() Unknown
Microsoft.AspNet.Session.dll!Microsoft.AspNet.Session.DistributedSession.TryGetValue(string key, out byte[] value) Unknown
Microsoft.AspNet.Http.Extensions.dll!Microsoft.AspNet.Http.SessionExtensions.Get(Microsoft.AspNet.Http.Features.ISession session, string key) Unknown
Microsoft.AspNet.Http.Extensions.dll!Microsoft.AspNet.Http.SessionExtensions.GetString(Microsoft.AspNet.Http.Features.ISession session, string key) Unknown
NLog.Web.ASPNET5.dll!NLog.Web.LayoutRenderers.AspNetSessionValueLayoutRenderer.DoAppend.AnonymousMethod__0(string k) Unknown
NLog.Web.ASPNET5.dll!NLog.Web.Internal.PropertyReader.GetValue(string key, System.Func<string, object> getVal, bool evaluateAsNestedProperties) Unknown
NLog.Web.ASPNET5.dll!NLog.Web.LayoutRenderers.AspNetSessionValueLayoutRenderer.DoAppend(System.Text.StringBuilder builder, NLog.LogEventInfo logEvent) Unknown
NLog.Web.ASPNET5.dll!NLog.Web.LayoutRenderers.AspNetLayoutRendererBase.Append(System.Text.StringBuilder builder, NLog.LogEventInfo logEvent) Unknown
NLog.dll!NLog.LayoutRenderers.LayoutRenderer.Render(System.Text.StringBuilder builder, NLog.LogEventInfo logEvent) Unknown
NLog.dll!NLog.Layouts.SimpleLayout.GetFormattedMessage(NLog.LogEventInfo logEvent) Unknown
NLog.dll!NLog.Layouts.Layout.Render(NLog.LogEventInfo logEvent) Unknown
NLog.dll!NLog.Layouts.Layout.Precalculate(NLog.LogEventInfo logEvent) Unknown
NLog.dll!NLog.Targets.Target.PrecalculateVolatileLayouts(NLog.LogEventInfo logEvent) Unknown
NLog.dll!NLog.Targets.Wrappers.AsyncTargetWrapper.Write(NLog.Common.AsyncLogEventInfo logEvent) Unknown
NLog.dll!NLog.Targets.Target.WriteAsyncLogEvent(NLog.Common.AsyncLogEventInfo logEvent) Unknown
NLog.dll!NLog.LoggerImpl.WriteToTargetWithFilterChain(NLog.Internal.TargetWithFilterChain targetListHead, NLog.LogEventInfo logEvent, NLog.Common.AsyncContinuation onException) Unknown
NLog.dll!NLog.LoggerImpl.Write(System.Type loggerType, NLog.Internal.TargetWithFilterChain targets, NLog.LogEventInfo logEvent, NLog.LogFactory factory) Unknown
NLog.dll!NLog.Logger.WriteToTargets(NLog.LogEventInfo logEvent) Unknown
NLog.dll!NLog.Logger.Log(NLog.LogEventInfo logEvent) Unknown
NLog.Extensions.Logging.dll!NLog.Extensions.Logging.NLogLogger.Log(Microsoft.Extensions.Logging.LogLevel logLevel, int eventId, object state, System.Exception exception, System.Func<object, System.Exception, string> formatter) Unknown
Microsoft.Extensions.Logging.dll!Microsoft.Extensions.Logging.Logger.Log(Microsoft.Extensions.Logging.LogLevel logLevel, int eventId, object state, System.Exception exception, System.Func<object, System.Exception, string> formatter) Unknown
Microsoft.Extensions.Logging.Abstractions.dll!Microsoft.Extensions.Logging.LoggerExtensions.LogWarning(Microsoft.Extensions.Logging.ILogger logger, string format, object[] args) Unknown