From 8b4d07e43a08aad09d63a4b2d7380cfd0f763a5d Mon Sep 17 00:00:00 2001 From: Bram Esendam Date: Wed, 28 Jul 2021 14:16:41 +0200 Subject: [PATCH] Removed try-catch --- .../LogEventPropertyValueExtensions.cs | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 deletions(-) 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)