Inheritance: Serilog.Events.LogEventPropertyValue
Beispiel #1
0
        /// <summary>
        /// Create properties from the provided log event.
        /// </summary>
        /// <param name="logEvent">The log event.</param>
        /// <returns>A dictionary with properties representing the log event.</returns>
        public static IReadOnlyDictionary<string, LogEventPropertyValue> GetOutputProperties(LogEvent logEvent)
        {
            var result = logEvent.Properties.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            // "Special" output properties like Message will override any properties with the same name
            // when used in format strings; this doesn't affect the rendering of the message template,
            // which uses only the log event properties.

            result[MessagePropertyName] = new LogEventPropertyMessageValue(logEvent.MessageTemplate, logEvent.Properties);
            result[TimestampPropertyName] = new ScalarValue(logEvent.Timestamp);
            result[LevelPropertyName] = new ScalarValue(logEvent.Level);
            result[NewLinePropertyName] = new ScalarValue(Environment.NewLine);

            var exception = logEvent.Exception == null ? "" : (logEvent.Exception + Environment.NewLine);
            result[ExceptionPropertyName] = new ScalarValue(exception);

            return result;
        }
        /// <summary>
        /// Create properties from the provided log event.
        /// </summary>
        /// <param name="logEvent">The log event.</param>
        /// <returns>A dictionary with properties representing the log event.</returns>
        public static IDictionary<string, LogEventPropertyValue> GetOutputProperties(LogEvent logEvent)
        {
            var result = logEvent.Properties.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            // "Special" output properties like Message will override any properties with the same name
            // when used in format strings; this doesn't affect the rendering of the message template,
            // which uses only the log event properties.

            result[MessagePropertyName] = new LogEventPropertyMessageValue(logEvent.MessageTemplate, logEvent.Properties);
            result[TimestampPropertyName] = new ScalarValue(logEvent.Timestamp);
            result[LevelPropertyName] = new ScalarValue(logEvent.Level);
            result[NewLinePropertyName] = new LiteralStringValue(Environment.NewLine);

            var exception = logEvent.Exception == null ? "" : (logEvent.Exception + Environment.NewLine);
            result[ExceptionPropertyName] = new LiteralStringValue(exception);

            return result;
        }