Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
BrammyS committed Jul 28, 2021
2 parents 22dbc9f + 8b4d07e commit 5408b89
Showing 1 changed file with 22 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,39 @@ public static class LogEventPropertyValueExtensions
/// </returns>
public static BsonValue ToBsonValue(this LogEventPropertyValue propertyValue, string? format = null, IFormatProvider? formatProvider = null)
{
try
if (propertyValue is ScalarValue scalar)
{
if (propertyValue is ScalarValue scalar)
{
return ConvertScalar(scalar.Value);
}
return ConvertScalar(scalar.Value);
}

if (propertyValue is DictionaryValue dict)
if (propertyValue is DictionaryValue dict)
{
var bsonDict = new Dictionary<BsonValue, BsonValue>();
foreach (var (key, value) in dict.Elements)
{
var bsonDict = new Dictionary<BsonValue, BsonValue>();
foreach (var (key, value) in dict.Elements)
{
bsonDict.Add(ConvertScalar(key), value.ToBsonValue(format, formatProvider));
}

return BsonValue.Create(bsonDict);
bsonDict.Add(ConvertScalar(key), value.ToBsonValue(format, formatProvider));
}

if (propertyValue is SequenceValue seq)
{
var bsonList = new List<BsonValue>();
foreach (var value in seq.Elements)
{
bsonList.Add(value.ToBsonValue(format, formatProvider));
}

return BsonValue.Create(bsonList);
}
return BsonValue.Create(bsonDict);
}

if (propertyValue is StructureValue str)
if (propertyValue is SequenceValue seq)
{
var bsonList = new List<BsonValue>();
foreach (var value in seq.Elements)
{
return BsonValue.Create(str.ToString(format, formatProvider));
bsonList.Add(value.ToBsonValue(format, formatProvider));
}

return BsonValue.Create(null);
return BsonValue.Create(bsonList);
}
catch (Exception e)

if (propertyValue is StructureValue str)
{
Console.WriteLine(e);
throw;
return BsonValue.Create(str.ToString(format, formatProvider));
}

return BsonValue.Create(null);
}

private static BsonValue ConvertScalar(object? value)
Expand Down

0 comments on commit 5408b89

Please sign in to comment.