Ejemplo n.º 1
0
        private static LoggerConfiguration LokiHttpImpl(
            this LoggerSinkConfiguration sinkConfiguration,
            LokiCredentials credentials,
            ILogLabelProvider logLabelProvider,
            IHttpClient httpClient,
            string outputTemplate,
            IFormatProvider formatProvider,
            int batchPostingLimit,
            int?queueLimit,
            TimeSpan?period)
        {
            var formatter = new LokiBatchFormatter(logLabelProvider ?? new DefaultLogLabelProvider());
            var client    = httpClient ?? new DefaultLokiHttpClient();

            if (client is LokiHttpClient c)
            {
                c.SetAuthCredentials(credentials);
            }

            return(sinkConfiguration.Http(LokiRouteBuilder.BuildPostUri(credentials.Url),
                                          batchFormatter: formatter,
                                          textFormatter: new MessageTemplateTextFormatter(outputTemplate, formatProvider),
                                          httpClient: client,
                                          batchPostingLimit: batchPostingLimit,
                                          queueLimit: queueLimit,
                                          period: period));
        }
Ejemplo n.º 2
0
        public void SetAuthCredentials(LokiCredentials credentials)
        {
            if (!(credentials is BasicAuthCredentials c))
            {
                return;
            }

            var headers = HttpClient.DefaultRequestHeaders;

            if (headers.Any(x => x.Key == "Authorization"))
            {
                return;
            }

            var token = Base64Encode($"{c.Username}:{c.Password}");

            headers.Add("Authorization", $"Basic {token}");
        }
Ejemplo n.º 3
0
 public static LoggerConfiguration LokiHttp(this LoggerSinkConfiguration sinkConfiguration, LokiCredentials credentials, ILogLabelProvider labelProvider = null, LokiHttpClient httpClient = null)
 => LokiHttpImpl(sinkConfiguration, credentials, labelProvider, httpClient);
Ejemplo n.º 4
0
        private static LoggerConfiguration LokiHttpImpl(this LoggerSinkConfiguration sinkConfiguration, LokiCredentials credentials, ILogLabelProvider logLabelProvider, IHttpClient httpClient)
        {
            var formatter = new LokiBatchFormatter(logLabelProvider?.GlobalLabels, logLabelProvider?.LabelNames, logLabelProvider.PreserveOriginalTimestamp);

            var client = httpClient ?? new LokiHttpClient();

            if (client is LokiHttpClient c)
            {
                c.SetAuthCredentials(credentials);
            }

            return(sinkConfiguration.Http(LokiRouteBuilder.BuildPostUri(credentials.Url), batchFormatter: formatter, httpClient: client));
        }
Ejemplo n.º 5
0
 public static LoggerConfiguration LokiHttp(this LoggerSinkConfiguration sinkConfiguration, LokiCredentials credentials, ILogLabelProvider labelProvider = null, LokiHttpClient httpClient = null, string outputTemplate = LokiSinkConfiguration.DefaultTemplate, IFormatProvider formatProvider = null)
 => LokiHttpImpl(sinkConfiguration, credentials, labelProvider, httpClient, outputTemplate, formatProvider);
        private static LoggerConfiguration LokiHttpImpl(this LoggerSinkConfiguration sinkConfiguration, LokiCredentials credentials, ILogLabelProvider logLabelProvider, IHttpClient httpClient)
        {
            var formatter = logLabelProvider != null ? new LokiBatchFormatter(logLabelProvider.GetLabels()) : new LokiBatchFormatter();

            var client = httpClient ?? new LokiHttpClient();

            if (client is LokiHttpClient c)
            {
                c.SetAuthCredentials(credentials);
            }

            return(sinkConfiguration.Http(LokiRouteBuilder.BuildPostUri(credentials.Url), batchFormatter: formatter, httpClient: client));
        }