public void MongoFieldTest1() { const string name = "Name"; var mf = new MongoField(name, _layout.Object); Assert.AreEqual(name, mf.Name); Assert.AreEqual(_layout.Object, mf.Layout); Assert.AreEqual("String", mf.BsonType); }
public void MongoFieldTest() { var mf = new MongoField(); Assert.IsNull(mf.Name); // ReSharper disable HeuristicUnreachableCode Assert.IsNull(mf.Layout); Assert.AreEqual("String", mf.BsonType); // ReSharper restore HeuristicUnreachableCode }
public void MongoFieldTest2() { const string name = "Name"; const string bsonType = "Wtf"; var mf = new MongoField(name, _layout.Object, bsonType); Assert.AreEqual(name, mf.Name); Assert.AreEqual(_layout.Object, mf.Layout); Assert.AreEqual(bsonType, mf.BsonType); }
private BsonValue GetValue(MongoField field, LogEventInfo logEvent) { var value = field.Layout.Render(logEvent); if (string.IsNullOrWhiteSpace(value)) { return(null); } value = value.Trim(); if (string.IsNullOrEmpty(field.BsonType) || string.Equals(field.BsonType, "String", StringComparison.OrdinalIgnoreCase)) { return(new BsonString(value)); } BsonValue bsonValue; if (string.Equals(field.BsonType, "Boolean", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryBoolean(value, out bsonValue)) { return(bsonValue); } if (string.Equals(field.BsonType, "DateTime", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryDateTime(value, out bsonValue)) { return(bsonValue); } if (string.Equals(field.BsonType, "Double", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryDouble(value, out bsonValue)) { return(bsonValue); } if (string.Equals(field.BsonType, "Int32", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryInt32(value, out bsonValue)) { return(bsonValue); } if (string.Equals(field.BsonType, "Int64", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryInt64(value, out bsonValue)) { return(bsonValue); } return(new BsonString(value)); }
private BsonValue GetValue(MongoField field, LogEventInfo logEvent) { var value = field.Layout.Render(logEvent); if (string.IsNullOrWhiteSpace(value)) { return(null); } value = value.Trim(); return(ConvertBsonValue(field, value)); }
private BsonValue ConvertBsonValue(MongoField field, string valueStr) { if (string.IsNullOrEmpty(field.BsonType) || string.Equals(field.BsonType, "String", StringComparison.OrdinalIgnoreCase)) { return(new BsonString(valueStr)); } BsonValue bsonValue; if (string.Equals(field.BsonType, "Boolean", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryBoolean(valueStr, out bsonValue)) { return(bsonValue); } if (string.Equals(field.BsonType, "DateTime", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryDateTime(valueStr, out bsonValue)) { return(bsonValue); } if (string.Equals(field.BsonType, "Double", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryDouble(valueStr, out bsonValue)) { return(bsonValue); } if (string.Equals(field.BsonType, "Int32", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryInt32(valueStr, out bsonValue)) { return(bsonValue); } if (string.Equals(field.BsonType, "Int64", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryInt64(valueStr, out bsonValue)) { return(bsonValue); } return(new BsonString(valueStr)); }
private BsonValue GetValue(MongoField field, LogEventInfo logEvent) { var value = field.Layout.Render(logEvent); if (string.IsNullOrWhiteSpace(value)) return null; value = value.Trim(); if (string.IsNullOrEmpty(field.BsonType) || string.Equals(field.BsonType, "String", StringComparison.OrdinalIgnoreCase)) return new BsonString(value); BsonValue bsonValue; if (string.Equals(field.BsonType, "Boolean", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryBoolean(value, out bsonValue)) return bsonValue; if (string.Equals(field.BsonType, "DateTime", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryDateTime(value, out bsonValue)) return bsonValue; if (string.Equals(field.BsonType, "Double", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryDouble(value, out bsonValue)) return bsonValue; if (string.Equals(field.BsonType, "Int32", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryInt32(value, out bsonValue)) return bsonValue; if (string.Equals(field.BsonType, "Int64", StringComparison.OrdinalIgnoreCase) && MongoConvert.TryInt64(value, out bsonValue)) return bsonValue; return new BsonString(value); }