Serilog.Events.LogEventPropertyValue.ToString C# (CSharp) Method

ToString() public method

Returns a string that represents the current object.
public ToString ( ) : string
return string
        public override string ToString()
        {
            return ToString(null, null);
        }

Same methods

LogEventPropertyValue::ToString ( string format, IFormatProvider formatProvider ) : string

Usage Example

        /// <summary>
        ///     Provide a decent string representation of the event property value
        /// </summary>
        /// <remarks>The built-in <c>ToString</c> wraps the string with quotes</remarks>
        /// <param name="logEventPropertyValue">Event property value to provide a string representation</param>
        public static string ToDecentString(this LogEventPropertyValue logEventPropertyValue)
        {
            Guard.NotNull(logEventPropertyValue, nameof(logEventPropertyValue));

            var propertyValueAsString = logEventPropertyValue.ToString().Trim();

            if (propertyValueAsString.StartsWith("\""))
            {
                propertyValueAsString = propertyValueAsString.Remove(0, 1);
            }

            if (propertyValueAsString.EndsWith("\""))
            {
                propertyValueAsString = propertyValueAsString.Remove(propertyValueAsString.Length - 1);
            }

            return(propertyValueAsString);
        }
LogEventPropertyValue