private string ConvertPropertiesToXmlStructure(IEnumerable <KeyValuePair <string, LogEventPropertyValue> > properties)
        {
            var options = _columnOptions.Properties;

            if (options.ExcludeAdditionalProperties)
            {
                properties = properties.Where(p => !_additionalDataColumnNames.Contains(p.Key));
            }

            var sb = new StringBuilder();

            sb.AppendFormat("<{0}>", options.RootElementName);

            foreach (var property in properties)
            {
                var value = XmlPropertyFormatter.Simplify(property.Value, options);
                if (options.OmitElementIfEmpty && string.IsNullOrEmpty(value))
                {
                    continue;
                }

                if (options.UsePropertyKeyAsElementName)
                {
                    sb.AppendFormat("<{0}>{1}</{0}>", XmlPropertyFormatter.GetValidElementName(property.Key), value);
                }
                else
                {
                    sb.AppendFormat("<{0} key='{1}'>{2}</{0}>", options.PropertyElementName, property.Key, value);
                }
            }

            sb.AppendFormat("</{0}>", options.RootElementName);

            return(sb.ToString());
        }
Example #2
0
        private string ConvertPropertiesToXmlStructure(IEnumerable <KeyValuePair <string, LogEventPropertyValue> > properties)
        {
            var options = columnOptions.Properties;

            if (options.ExcludeAdditionalProperties)
            {
                properties = properties.Where(p => !additionalColumnNames.Contains(p.Key));
            }

            if (options.PropertiesFilter != null)
            {
                try
                {
                    properties = properties.Where(p => options.PropertiesFilter(p.Key));
                }
                catch (Exception ex)
                {
                    SelfLog.WriteLine("Unable to filter properties to store in {0} due to following error: {1}", this, ex);
                }
            }

            var sb = new StringBuilder();

            sb.AppendFormat("<{0}>", options.RootElementName);

            foreach (var property in properties)
            {
                var value = XmlPropertyFormatter.Simplify(property.Value, options);
                if (options.OmitElementIfEmpty && string.IsNullOrEmpty(value))
                {
                    continue;
                }

                if (options.UsePropertyKeyAsElementName)
                {
                    sb.AppendFormat("<{0}>{1}</{0}>", XmlPropertyFormatter.GetValidElementName(property.Key), value);
                }
                else
                {
                    sb.AppendFormat("<{0} key='{1}'>{2}</{0}>", options.PropertyElementName, property.Key, value);
                }
            }

            sb.AppendFormat("</{0}>", options.RootElementName);

            return(sb.ToString());
        }
        static string ConvertPropertiesToXmlStructure(
            IEnumerable <KeyValuePair <string, LogEventPropertyValue> > properties)
        {
            var sb = new StringBuilder();

            sb.Append("<properties>");

            foreach (var property in properties)
            {
                sb.AppendFormat("<property key='{0}'>{1}</property>", property.Key,
                                XmlPropertyFormatter.Simplify(property.Value));
            }

            sb.Append("</properties>");

            return(sb.ToString());
        }
Example #4
0
        private string ConvertPropertiesToXmlStructure(IEnumerable <KeyValuePair <string, LogEventPropertyValue> > properties)
        {
            if (_excludeAdditionalProperties)
            {
                properties = properties.Where(p => !_additionalDataColumnNames.Contains(p.Key));
            }

            var sb = new StringBuilder();

            sb.Append("<properties>");

            foreach (var property in properties)
            {
                sb.AppendFormat("<property key='{0}'>{1}</property>", property.Key,
                                XmlPropertyFormatter.Simplify(property.Value));
            }

            sb.Append("</properties>");

            return(sb.ToString());
        }