Example #1
0
        public static StringBuilder WriteMessage(this StringBuilder sb, LogstashEvent evt)
        {
            sb.WriteString(nameof(LogstashEvent.message), evt.message);

            if (evt.exception != null)
            {
                sb.Append(",")
                .Append("\"exception\":{")
                .WriteString(nameof(LogstashException.exception_class), evt.exception.exception_class).Append(",")
                .WriteString(nameof(LogstashException.exception_message), evt.exception.exception_message).Append(",")
                .WriteString(nameof(LogstashException.stacktrace), evt.exception.stacktrace)
                .Append("}");
            }
            return(sb);
        }
Example #2
0
        public static string ToJson(this LogstashEvent evt)
        {
            var logstash = new StringBuilder();

            logstash.Append("{")
            .WriteValueObject("@version", evt.version).Append(",")
            .WriteString("@timestamp", evt.timestamp).Append(",")
            .WriteString(nameof(LogstashEvent.source_host), evt.source_host).Append(",")
            .WriteString(nameof(LogstashEvent.app), evt.app).Append(",")
            .WriteString(nameof(LogstashEvent.thread_name), evt.thread_name).Append(",")
            .WriteString(nameof(LogstashEvent.@class), evt.@class).Append(",")
            .WriteString(nameof(LogstashEvent.method), evt.method).Append(",")
            .WriteString(nameof(LogstashEvent.line_number), evt.line_number).Append(",")
            .WriteString(nameof(LogstashEvent.level), evt.level).Append(",")
            .WriteString(nameof(LogstashEvent.logger_name), evt.logger_name).Append(",")
            .WriteMessage(evt)
            .Append("}");
            return(logstash.ToString());
        }