示例#1
0
        private string _format; // could be json or raw

        // Constructor
        public LokiClient(HttpClient httpClient, CloudFrontLogParser cloudFrontLogParser, IConfiguration config)
        {
            _httpClient          = httpClient;
            _cloudFrontLogParser = cloudFrontLogParser;
            _endpoint            = config["LokiEndpoint"];
            _username            = config["LokiUsername"];
            _password            = config["LokiPassword"];
            _format = config["LokiFormat"];

            ConfigureHttpClient();
        }
        public LokiLogEntry(Dictionary <string, string> labels, CloudFrontLogParser cloudFrontLogParser, string format)
        {
            string     epochNanoSeconds = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString() + "000000";
            LokiStream lokiStream;

            if (format == "raw")
            {
                lokiStream = new LokiStream(labels, epochNanoSeconds, cloudFrontLogParser.ContentRaw);
            }
            else   // json
            {
                string json = JsonSerializer.Serialize <Dictionary <string, string> >(cloudFrontLogParser.ContentDictionary);
                lokiStream = new LokiStream(labels, epochNanoSeconds, json);
            }
            Streams = new List <LokiStream>();
            Streams.Add(lokiStream);
        }