diff --git a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventPropertyValueExtensions.cs b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventPropertyValueExtensions.cs index ff158fa..c77a2dc 100644 --- a/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventPropertyValueExtensions.cs +++ b/src/Serilog.Sinks.Mongodb.TimeSeries/Extensions/LogEventPropertyValueExtensions.cs @@ -18,47 +18,39 @@ public static class LogEventPropertyValueExtensions /// 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(); + foreach (var (key, value) in dict.Elements) { - var bsonDict = new Dictionary(); - 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(); - 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(); + 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)