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

Commit

Permalink
Issue nr: 14594 - removing old implementation where fields where dot-… (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
rajmondburgaj authored Sep 16, 2020
1 parent 9fe222c commit 988a4ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Changelog

* Disable dot-escaping for field names, because ELK already supports dots in field names.

8.2
* Allow the use of templateCustomSettings when reading from settings json (#315)
* Updated Elasticsearch.Net dependency #340
Expand Down
64 changes: 17 additions & 47 deletions src/Serilog.Formatting.Elasticsearch/ElasticsearchJsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,45 +115,6 @@ protected override void WriteProperties(IReadOnlyDictionary<string, LogEventProp
output.Write("}");
}

/// <summary>
/// Escape the name of the Property before calling ElasticSearch
/// </summary>
protected override void WriteDictionary(IReadOnlyDictionary<ScalarValue, LogEventPropertyValue> elements, TextWriter output)
{
var escaped = elements.ToDictionary(e => DotEscapeFieldName(e.Key), e => e.Value);

base.WriteDictionary(escaped, output);
}

/// <summary>
/// Escape the name of the Property before calling ElasticSearch
/// </summary>
protected override void WriteJsonProperty(string name, object value, ref string precedingDelimiter, TextWriter output)
{
name = DotEscapeFieldName(name);

base.WriteJsonProperty(name, value, ref precedingDelimiter, output);
}

/// <summary>
/// Escapes Dots in Strings and does nothing to objects
/// </summary>
protected virtual ScalarValue DotEscapeFieldName(ScalarValue value)
{
return value.Value is string s ? new ScalarValue(DotEscapeFieldName(s)) : value;
}

/// <summary>
/// Dots are not allowed in Field Names, replaces '.' with '/'
/// https://github.com/elastic/elasticsearch/issues/14594
/// </summary>
protected virtual string DotEscapeFieldName(string value)
{
if (value == null) return null;

return value.Replace('.', '/');
}

/// <summary>
/// Writes out the attached exception
/// </summary>
Expand All @@ -171,15 +132,24 @@ protected override void WriteException(Exception exception, ref string delim, Te

private void WriteExceptionSerializationInfo(Exception exception, ref string delim, TextWriter output, int depth)
{
output.Write(delim);
output.Write("{");
delim = "";
WriteSingleException(exception, ref delim, output, depth);
output.Write("}");
while (true)
{
output.Write(delim);
output.Write("{");
delim = "";
WriteSingleException(exception, ref delim, output, depth);
output.Write("}");

delim = ",";
if (exception.InnerException != null && depth < 20)
this.WriteExceptionSerializationInfo(exception.InnerException, ref delim, output, ++depth);
delim = ",";
if (exception.InnerException != null && depth < 20)
{
exception = exception.InnerException;
depth = ++depth;
continue;
}

break;
}
}

/// <summary>
Expand Down

0 comments on commit 988a4ee

Please sign in to comment.