public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result) { result = null; var wrapper = value as WrappedJObject; if (wrapper == null) { return false; } var data = wrapper.Value as JObject; if (data == null) { return false; } var values = ReadProperties(data); result = new StructureValue(values); return true; }
public void StructuresFormatAsAnObject() { var structure = new StructureValue(new[] { new LogEventProperty("A", new ScalarValue(123)) }, "T"); var f = Format(structure); Assert.Equal("{\"A\":123,\"_typeTag\":\"T\"}", f); }
public void TypeTagCanBeOverridden() { var structure = new StructureValue(new LogEventProperty[0], "T"); var formatter = new JsonValueFormatter("$type"); var output = new StringWriter(); formatter.Format(structure, output); var f = output.ToString(); Assert.Equal("{\"$type\":\"T\"}", f); }
public void WhenNullNoTypeTagIsWritten() { var structure = new StructureValue(new LogEventProperty[0], "T"); var formatter = new JsonValueFormatter(null); var output = new StringWriter(); formatter.Format(structure, output); var f = output.ToString(); Assert.Equal("{}", f); }
public void AStructureSerializesAsAnObject() { var value = Some.Int(); var memberProp = new LogEventProperty(Some.String(), new ScalarValue(value)); var structure = new StructureValue(new[] { memberProp }); var structureProp = new LogEventProperty(Some.String(), structure); var @event = Some.LogEvent(); @event.AddOrUpdateProperty(structureProp); var formatted = FormatJson(@event); var result = (int)formatted.Properties[structureProp.Name][memberProp.Name]; Assert.AreEqual(value, result); }