Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG 6054: Added NdcItemSeparator to ${log4jxmlevent} and NLogViewer t…

…arget.
  • Loading branch information...
commit 90ce7aaf821e17723d52e92361f485e9394c2658 1 parent d36726d
@jkowalski authored
View
10 src/NLog/LayoutRenderers/Log4JXmlEventLayoutRenderer.cs
@@ -63,6 +63,7 @@ public class Log4JXmlEventLayoutRenderer : LayoutRenderer, IUsesStackTrace
public Log4JXmlEventLayoutRenderer()
{
this.IncludeNLogData = true;
+ this.NdcItemSeparator = " ";
#if NET_CF
this.AppInfo = ".NET CF Application";
#elif SILVERLIGHT
@@ -123,6 +124,13 @@ public Log4JXmlEventLayoutRenderer()
public bool IncludeNdc { get; set; }
/// <summary>
+ /// Gets or sets the NDC item separator.
+ /// </summary>
+ /// <docgen category='Payload Options' order='10' />
+ [DefaultValue(" ")]
+ public string NdcItemSeparator { get; set; }
+
+ /// <summary>
/// Gets the level of stack trace information required by the implementing class.
/// </summary>
StackTraceUsage IUsesStackTrace.StackTraceUsage
@@ -179,7 +187,7 @@ protected override void Append(StringBuilder builder, LogEventInfo logEvent)
xtw.WriteElementString("log4j", "message", dummyNamespace, logEvent.FormattedMessage);
if (this.IncludeNdc)
{
- xtw.WriteElementString("log4j", "NDC", dummyNamespace, string.Join(" ", NestedDiagnosticsContext.GetAllMessages()));
+ xtw.WriteElementString("log4j", "NDC", dummyNamespace, string.Join(this.NdcItemSeparator, NestedDiagnosticsContext.GetAllMessages()));
}
#if !NET_CF
View
10 src/NLog/Targets/NLogViewerTarget.cs
@@ -148,6 +148,16 @@ public bool IncludeNdc
}
/// <summary>
+ /// Gets or sets the NDC item separator.
+ /// </summary>
+ /// <docgen category='Payload Options' order='10' />
+ public string NdcItemSeparator
+ {
+ get { return this.Renderer.NdcItemSeparator; }
+ set { this.Renderer.NdcItemSeparator = value; }
+ }
+
+ /// <summary>
/// Gets the collection of parameters. Each parameter contains a mapping
/// between NLog layout and a named parameter.
/// </summary>
View
6 tests/NLog.UnitTests/LayoutRenderers/Log4JXmlTests.cs
@@ -58,12 +58,12 @@ namespace NLog.UnitTests.LayoutRenderers
public class Log4JXmlTests : NLogTestBase
{
[Test]
- public void Test1()
+ public void Log4JXmlTest()
{
LogManager.Configuration = CreateConfigurationFromString(@"
<nlog throwExceptions='true'>
<targets>
- <target name='debug' type='Debug' layout='${log4jxmlevent:includeCallSite=true:includeSourceInfo=true:includeMdc=true:includendc=true:includenlogdata=true}' />
+ <target name='debug' type='Debug' layout='${log4jxmlevent:includeCallSite=true:includeSourceInfo=true:includeMdc=true:includendc=true:ndcItemSeparator=\:\::includenlogdata=true}' />
</targets>
<rules>
<logger name='*' minlevel='Debug' writeTo='debug' />
@@ -119,7 +119,7 @@ public void Test1()
case "NDC":
reader.Read();
- Assert.AreEqual("baz3 baz2 baz1", reader.Value);
+ Assert.AreEqual("baz3::baz2::baz1", reader.Value);
break;
#if !NET_CF
Please sign in to comment.
Something went wrong with that request. Please try again.