Пример #1
0
        private static void GenerateEntry(LogEvent logEvent, ITextFormatter formatter, LokiStream stream, IEnumerable <string> labels)
        {
            var buffer = new StringWriter(new StringBuilder(DefaultWriteBufferCapacity));

            if (formatter is ILabelAwareTextFormatter labelAwareTextFormatter)
            {
                labelAwareTextFormatter.Format(logEvent, buffer, labels);
            }
            else
            {
                formatter.Format(logEvent, buffer);
            }

            stream.AddEntry(logEvent.Timestamp, buffer.ToString().TrimEnd('\r', '\n'));
        }
        private static void GenerateEntry(LogEvent logEvent, LokiStream stream)
        {
            var sb = new StringBuilder();

            sb.AppendLine(logEvent.RenderMessage());

            if (logEvent.Exception != null)
            {
                var ex = logEvent.Exception;
                while (ex != null)
                {
                    sb.AppendLine(ex.Message);
                    sb.AppendLine(ex.StackTrace);
                    ex = ex.InnerException;
                }
            }

            stream.AddEntry(logEvent.Timestamp, sb.ToString().TrimEnd('\r', '\n'));
        }
Пример #3
0
    private void GenerateEntry(
        LokiLogEvent lokiLogEvent,
        ITextFormatter formatter,
        LokiStream stream)
    {
        var buffer = new StringWriter(new StringBuilder(DefaultWriteBufferCapacity));

        var logEvent  = lokiLogEvent.LogEvent;
        var timestamp = logEvent.Timestamp;

        if (_useInternalTimestamp)
        {
            logEvent.AddPropertyIfAbsent(
                new LogEventProperty("Timestamp", new ScalarValue(timestamp)));
            timestamp = lokiLogEvent.InternalTimestamp;
        }

        formatter.Format(logEvent, buffer);

        stream.AddEntry(timestamp, buffer.ToString().TrimEnd('\r', '\n'));
    }