Skip to content

Commit 0dce471

Browse files
committed
Include the index in the property name when formatting a SequenceValue
I had previously hesitated a lot to include the index and when improving the example code in the README I stumbled on a problem with Log4View: it can't handle XML with two identical properties (no error is displayed but no log is displayed at all either). Before this commit (unreadable with Log4View): ``` <log4net:properties> <log4net:data name="Args" value="--first-argument" /> <log4net:data name="Args" value="--second-argument" /> </log4net:properties> ``` After this commit (no problem with Log4View): ``` <log4net:properties> <log4net:data name="Args[0]" value="--first-argument" /> <log4net:data name="Args[1]" value="--second-argument" /> </log4net:properties> ```
1 parent 6cae94a commit 0dce471

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Log4NetTextFormatter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ private void WriteDictionaryProperty(XmlWriter writer, string propertyName, Dict
291291
/// <param name="sequenceValue">The <see cref="SequenceValue"/> to write.</param>
292292
private void WriteSequenceProperty(XmlWriter writer, string propertyName, SequenceValue sequenceValue)
293293
{
294-
foreach (var value in sequenceValue.Elements)
294+
foreach (var (value, i) in sequenceValue.Elements.Select((e, i) => (e, i)))
295295
{
296-
WritePropertyElement(writer, propertyName, value);
296+
WritePropertyElement(writer,$"{propertyName}[{i}]", value);
297297
}
298298
}
299299

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<log4net:event timestamp="2003-01-04T15:09:26.535+01:00" level="INFO" xmlns:log4net="http://logging.apache.org/log4net/schemas/log4net-events-1.2/">
22
<log4net:properties>
3-
<log4net:data name="Sequence" value="1" />
4-
<log4net:data name="Sequence" value="two" />
5-
<log4net:data name="Sequence" value="[(1: &quot;one&quot;), (&quot;two&quot;: 2)]" />
3+
<log4net:data name="Sequence[0]" value="1" />
4+
<log4net:data name="Sequence[1]" value="two" />
5+
<log4net:data name="Sequence[2]" value="[(1: &quot;one&quot;), (&quot;two&quot;: 2)]" />
66
</log4net:properties>
77
<log4net:message><![CDATA[Hello from Serilog]]></log4net:message>
88
</log4net:event>

0 commit comments

Comments
 (0)