Serilog.Events.ScalarValue.Render C# (CSharp) Method

Render() public method

Render the value to the output.
public Render ( TextWriter output, string format = null, IFormatProvider formatProvider = null ) : void
output System.IO.TextWriter The output.
format string A format string applied to the value, or null.
formatProvider IFormatProvider A format provider to apply to the value, or null to use the default.
return void
        public override void Render(TextWriter output, string format = null, IFormatProvider formatProvider = null)
        {
            if (output == null) throw new ArgumentNullException(nameof(output));

            if (Value == null)
            {
                output.Write("null");
                return;
            }

            var s = Value as string;
            if (s != null)
            {
                if (format != "l")
                {
                    output.Write("\"");
                    output.Write(s.Replace("\"", "\\\""));
                    output.Write("\"");
                }
                else
                {
                    output.Write(s);
                }
                return;
            }

            if (formatProvider != null)
            {
                var custom = (ICustomFormatter)formatProvider.GetFormat(typeof(ICustomFormatter));
                if (custom != null)
                {
                    output.Write(custom.Format(format, Value, formatProvider));
                    return;
                }
            }

            var f = Value as IFormattable;
            if (f != null)
            {
                output.Write(f.ToString(format, formatProvider ?? CultureInfo.InvariantCulture));
            }
            else
            {
                output.Write(Value.ToString());
            }
        }