2020-08-27 19:28:36 +00:00
|
|
|
using Serilog.Formatting.Elasticsearch;
|
|
|
|
using Serilog.Formatting.Json;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Core;
|
|
|
|
|
|
|
|
public class ScalarFormatting
|
2020-08-27 19:28:36 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
private static bool Write(object value, TextWriter output)
|
2020-08-27 19:28:36 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
if (value is SystemId si)
|
|
|
|
output.Write(si.Value);
|
|
|
|
else if (value is MemberId mi)
|
|
|
|
output.Write(mi.Value);
|
|
|
|
else if (value is GroupId gi)
|
|
|
|
output.Write(gi.Value);
|
|
|
|
else if (value is SwitchId swi)
|
|
|
|
output.Write(swi.Value);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
2020-08-27 19:28:36 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
private static void WriteV(object value, TextWriter output) => Write(value, output);
|
2020-08-27 19:28:36 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class Elasticsearch: ElasticsearchJsonFormatter
|
|
|
|
{
|
|
|
|
public Elasticsearch(bool omitEnclosingObject = false, string closingDelimiter = null,
|
|
|
|
bool renderMessage = true, IFormatProvider formatProvider = null,
|
|
|
|
ISerializer serializer = null, bool inlineFields = false,
|
|
|
|
bool renderMessageTemplate = true, bool formatStackTraceAsArray = false) : base(
|
|
|
|
omitEnclosingObject, closingDelimiter, renderMessage, formatProvider, serializer, inlineFields,
|
|
|
|
renderMessageTemplate, formatStackTraceAsArray)
|
2020-08-27 19:28:36 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
AddLiteralWriter(typeof(SystemId), WriteV);
|
|
|
|
AddLiteralWriter(typeof(MemberId), WriteV);
|
|
|
|
AddLiteralWriter(typeof(GroupId), WriteV);
|
|
|
|
AddLiteralWriter(typeof(SwitchId), WriteV);
|
2020-08-27 19:28:36 +00:00
|
|
|
}
|
2021-11-27 02:10:56 +00:00
|
|
|
}
|
2020-08-27 19:28:36 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public class JsonValue: JsonValueFormatter
|
|
|
|
{
|
|
|
|
protected override void FormatLiteralValue(object value, TextWriter output)
|
2020-08-27 19:28:36 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
if (Write(value, output))
|
|
|
|
return;
|
|
|
|
base.FormatLiteralValue(value, output);
|
2020-08-27 19:28:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|