IEnumerable <LogEventProperty> ConstructNamedProperties(MessageTemplate template, object[] messageTemplateParameters)
        {
            var namedProperties = template.NamedProperties;

            if (namedProperties == null)
            {
                return(Enumerable.Empty <LogEventProperty>());
            }

            var matchedRun = namedProperties.Length;

            if (namedProperties.Length != messageTemplateParameters.Length)
            {
                matchedRun = Math.Min(namedProperties.Length, messageTemplateParameters.Length);
                SelfLog.WriteLine("Named property count does not match parameter count: {0}", template);
            }

            var result = new LogEventProperty[messageTemplateParameters.Length];

            for (var i = 0; i < matchedRun; ++i)
            {
                var property = template.NamedProperties[i];
                var value    = messageTemplateParameters[i];
                result[i] = ConstructProperty(property, value);
            }

            for (var i = matchedRun; i < messageTemplateParameters.Length; ++i)
            {
                var value = _valueConverter.CreatePropertyValue(messageTemplateParameters[i]);
                result[i] = new LogEventProperty("__" + i, value);
            }
            return(result);
        }
示例#2
0
            public LogEventPropertyValue CreatePropertyValue(object value, Destructuring destructuring)
            {
                var storedDepth = _currentDepth;

                var result = DefaultIfMaximumDepth(storedDepth) ??
                             _propertyValueConverter.CreatePropertyValue(value, destructuring, storedDepth + 1);

                _currentDepth = storedDepth;

                return(result);
            }
 public LogEventPropertyValue CreatePropertyValue(object value, bool destructureObjects = false)
 {
     return(_propertyValueConverter.CreatePropertyValue(value, destructureObjects));
 }