in src/Serilog.Sinks.AzureDataExplorer/Extensions/LogEventExtensions.cs [92:156]
private static object Simplify(LogEventPropertyValue data)
{
if (data is ScalarValue value)
{
return value.Value;
}
// ReSharper disable once SuspiciousTypeConversion.Global
if (data is DictionaryValue dictValue)
{
var expObject = new Dictionary<string, object>(dictValue.Elements.Count);
foreach (var item in dictValue.Elements)
{
if (item.Key.Value is string key)
{
expObject.Add(key, Simplify(item.Value));
}
}
return expObject;
}
if (data is SequenceValue seq)
{
return seq.Elements.Select(Simplify).ToArray();
}
if (data is not StructureValue str)
{
return null;
}
{
try
{
if (str.TypeTag == null)
{
return str.Properties.ToDictionary(p => p.Name, p => Simplify(p.Value));
}
if (!str.TypeTag.StartsWith("DictionaryEntry") && !str.TypeTag.StartsWith("KeyValuePair"))
{
return str.Properties.ToDictionary(p => p.Name, p => Simplify(p.Value));
}
var key = Simplify(str.Properties[0].Value);
if (key == null)
{
return null;
}
return new Dictionary<string, object>(1)
{
{ key!.ToString()!, Simplify(str.Properties[1].Value) }
};
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
return null;
}