Serilog.Parsing.PropertyToken.Render C# (CSharp) Method

Render() public method

Render the token to the output.
public Render ( LogEventPropertyValue>.IReadOnlyDictionary properties, TextWriter output, IFormatProvider formatProvider = null ) : void
properties LogEventPropertyValue>.IReadOnlyDictionary Properties that may be represented by the token.
output TextWriter Output for the rendered string.
formatProvider IFormatProvider Supplies culture-specific formatting information, or null.
return void
        public override void Render(IReadOnlyDictionary<string, LogEventPropertyValue> properties, TextWriter output, IFormatProvider formatProvider = null)
        {
            if (properties == null) throw new ArgumentNullException(nameof(properties));
            if (output == null) throw new ArgumentNullException(nameof(output));

            LogEventPropertyValue propertyValue;
            if (!properties.TryGetValue(PropertyName, out propertyValue))
            {
                output.Write(_rawText);
                return;
            }

            if (!Alignment.HasValue)
            {
                propertyValue.Render(output, Format, formatProvider);
                return;
            }

            var valueOutput = new StringWriter();
            propertyValue.Render(valueOutput, Format, formatProvider);
            var value = valueOutput.ToString();

            if (value.Length >= Alignment.Value.Width)
            {
                output.Write(value);
                return;
            }

            Padding.Apply(output, value, Alignment.Value);
        }