Inheritance: Serilog.Events.LogEventPropertyValue
コード例 #1
0
ファイル: OutputProperties.cs プロジェクト: serilog/serilog
        /// <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 LogEventLevelValue(logEvent.Level);
            result[NewLinePropertyName] = new LiteralStringValue(Environment.NewLine);

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

            return result;
        }
コード例 #2
0
ファイル: OutputProperties.cs プロジェクト: starcake/serilog
        /// <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 LogEventLevelValue(logEvent.Level);
            result[NewLinePropertyName]   = new LiteralStringValue(Environment.NewLine);

            var exception = logEvent.Exception == null ? "" : (logEvent.Exception + Environment.NewLine);

            result[ExceptionPropertyName] = new LiteralStringValue(exception);

            return(result);
        }