Skip to content

Commit

Permalink
Fix stackoverflow by using context.Items
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed Apr 2, 2016
1 parent 5be7b27 commit f43eb18
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
#if !DNX
using System.Web;
#else
Expand Down Expand Up @@ -76,10 +77,37 @@ protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
#if !DNX
var value = PropertyReader.GetValue(Variable, k => context.Session[k], EvaluateAsNestedProperties);
#else
var value = PropertyReader.GetValue(Variable, k => context.Session.GetString(k), EvaluateAsNestedProperties);
if (context.Items == null)
{
return;
}

//because session.get / session.getstring also creating log messages in some cases, this could lead to stackoverflow issues.
//We remember on the context.Items that we are looking up a session value so we prevent stackoverflows
if (context.Items.ContainsKey(NLogRetrievingSessionValue))
{
//prevent stackoverflow
return;
}

context.Items[NLogRetrievingSessionValue] = true;
object value;
try
{
value = PropertyReader.GetValue(Variable, k => context.Session.GetString(k), EvaluateAsNestedProperties);
}
finally
{
context.Items.Remove(NLogRetrievingSessionValue);
}



#endif

builder.Append(Convert.ToString(value, CultureInfo.CurrentUICulture));
}

private const string NLogRetrievingSessionValue = "NLogRetrievingSessionValue";
}
}

0 comments on commit f43eb18

Please sign in to comment.