int RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary <string, LogEventPropertyValue> properties, TextWriter output)
        {
            if (!properties.TryGetValue(pt.PropertyName, out var propertyValue))
            {
                using (_theme.Apply(output, HtmlThemeStyle.Invalid))
                    output.Write(pt.ToString());
                return(0);
            }

            if (!pt.Alignment.HasValue)
            {
                return(RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format));
            }

            return(RenderAlignedPropertyTokenUnbuffered(pt, output, propertyValue));
        }
Example #2
0
        private int RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary <string, LogEventPropertyValue> properties, TextWriter output)
        {
            if (!properties.TryGetValue(pt.PropertyName, out var propertyValue))
            {
                var count = 0;
                using (_theme.Apply(output, RichTextBoxThemeStyle.Invalid, ref count))
                {
                    output.Write(SpecialCharsEscaping.Apply(pt.ToString(), ref count));
                }

                return(count);
            }

            if (!pt.Alignment.HasValue)
            {
                return(RenderValue(_theme, _valueFormatter, propertyValue, output, pt.Format));
            }

            var valueOutput = new StringWriter();

            if (!_theme.CanBuffer)
            {
                return(RenderAlignedPropertyTokenUnbuffered(pt, output, propertyValue));
            }

            var invisibleCount = RenderValue(_theme, _valueFormatter, propertyValue, valueOutput, pt.Format);

            var value = valueOutput.ToString();

            if (value.Length - invisibleCount >= pt.Alignment.Value.Width)
            {
                output.Write(value);
            }
            else
            {
                Padding.Apply(output, value, pt.Alignment.Value.Widen(invisibleCount));
            }

            return(invisibleCount);
        }