Skip to content

Commit d189cf4

Browse files
committed
Fix for Log4Net Context Stacks in v1.2.10 project
1 parent 0641790 commit d189cf4

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Src/StackifyLib.log4net.v1_2_10/StackifyAppender.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,19 @@ private Dictionary<string, object> GetDiagnosticContextProperties()
316316

317317
if (mdcValue != null)
318318
{
319-
properties[mdcKey.ToLower()] = mdcValue;
319+
// Check if the property is a Log4net Context Stack,
320+
// If it is, then we want to read it as a string as that is
321+
// the expected behavior for a Log4Net Appender.
322+
var tcs = mdcValue as Apache_log4net.Util.ThreadContextStack;
323+
if (tcs != null)
324+
{
325+
properties[mdcKey.ToLower()] = tcs.ToString();
326+
}
327+
else
328+
{
329+
// for anything else, we will let Json.Net take care of it.
330+
properties[mdcKey.ToLower()] = mdcValue;
331+
}
320332
}
321333
}
322334

@@ -326,7 +338,19 @@ private Dictionary<string, object> GetDiagnosticContextProperties()
326338

327339
if (mdcValue != null)
328340
{
329-
properties[mdcKey.ToLower()] = mdcValue;
341+
// Check if the property is a Log4net Context Stack,
342+
// If it is, then we want to read it as a string as that is
343+
// the expected behavior for a Log4Net Appender.
344+
var tcs = mdcValue as Apache_log4net.Util.ThreadContextStack;
345+
if (tcs != null)
346+
{
347+
properties[mdcKey.ToLower()] = tcs.ToString();
348+
}
349+
else
350+
{
351+
// for anything else, we will let Json.Net take care of it.
352+
properties[mdcKey.ToLower()] = mdcValue;
353+
}
330354
}
331355
}
332356

0 commit comments

Comments
 (0)