Skip to content
This repository was archived by the owner on Jun 1, 2024. It is now read-only.

Commit 988a4ee

Browse files
Issue nr: 14594 - removing old implementation where fields where dot-… (#351)
* Issue nr: 14594 - removing old implementation where fields where dot-escaped due to old ELK not supporting it. But now this is supported, therefore there is no need to escape it anylonger. * Update CHANGES.md
1 parent 9fe222c commit 988a4ee

File tree

2 files changed

+19
-47
lines changed

2 files changed

+19
-47
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Changelog
22

3+
* Disable dot-escaping for field names, because ELK already supports dots in field names.
4+
35
8.2
46
* Allow the use of templateCustomSettings when reading from settings json (#315)
57
* Updated Elasticsearch.Net dependency #340

src/Serilog.Formatting.Elasticsearch/ElasticsearchJsonFormatter.cs

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -115,45 +115,6 @@ protected override void WriteProperties(IReadOnlyDictionary<string, LogEventProp
115115
output.Write("}");
116116
}
117117

118-
/// <summary>
119-
/// Escape the name of the Property before calling ElasticSearch
120-
/// </summary>
121-
protected override void WriteDictionary(IReadOnlyDictionary<ScalarValue, LogEventPropertyValue> elements, TextWriter output)
122-
{
123-
var escaped = elements.ToDictionary(e => DotEscapeFieldName(e.Key), e => e.Value);
124-
125-
base.WriteDictionary(escaped, output);
126-
}
127-
128-
/// <summary>
129-
/// Escape the name of the Property before calling ElasticSearch
130-
/// </summary>
131-
protected override void WriteJsonProperty(string name, object value, ref string precedingDelimiter, TextWriter output)
132-
{
133-
name = DotEscapeFieldName(name);
134-
135-
base.WriteJsonProperty(name, value, ref precedingDelimiter, output);
136-
}
137-
138-
/// <summary>
139-
/// Escapes Dots in Strings and does nothing to objects
140-
/// </summary>
141-
protected virtual ScalarValue DotEscapeFieldName(ScalarValue value)
142-
{
143-
return value.Value is string s ? new ScalarValue(DotEscapeFieldName(s)) : value;
144-
}
145-
146-
/// <summary>
147-
/// Dots are not allowed in Field Names, replaces '.' with '/'
148-
/// https://github.com/elastic/elasticsearch/issues/14594
149-
/// </summary>
150-
protected virtual string DotEscapeFieldName(string value)
151-
{
152-
if (value == null) return null;
153-
154-
return value.Replace('.', '/');
155-
}
156-
157118
/// <summary>
158119
/// Writes out the attached exception
159120
/// </summary>
@@ -171,15 +132,24 @@ protected override void WriteException(Exception exception, ref string delim, Te
171132

172133
private void WriteExceptionSerializationInfo(Exception exception, ref string delim, TextWriter output, int depth)
173134
{
174-
output.Write(delim);
175-
output.Write("{");
176-
delim = "";
177-
WriteSingleException(exception, ref delim, output, depth);
178-
output.Write("}");
135+
while (true)
136+
{
137+
output.Write(delim);
138+
output.Write("{");
139+
delim = "";
140+
WriteSingleException(exception, ref delim, output, depth);
141+
output.Write("}");
179142

180-
delim = ",";
181-
if (exception.InnerException != null && depth < 20)
182-
this.WriteExceptionSerializationInfo(exception.InnerException, ref delim, output, ++depth);
143+
delim = ",";
144+
if (exception.InnerException != null && depth < 20)
145+
{
146+
exception = exception.InnerException;
147+
depth = ++depth;
148+
continue;
149+
}
150+
151+
break;
152+
}
183153
}
184154

185155
/// <summary>

0 commit comments

Comments
 (0)