A value represented as a collection of name-value properties.
Inheritance: LogEventPropertyValue
 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;
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 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);
        }