private static LoggerConfiguration LokiHttpImpl(this LoggerSinkConfiguration serilogConfig, LokiSinkConfiguration lokiConfig)
        {
            var formatter = new LokiBatchFormatter();

            formatter.FormatterStrategy  = lokiConfig.LokiFormatterStrategy;
            formatter.PropertiesAsLabels = lokiConfig.PropertiesAsLabels ?? new List <string>();
            formatter.PropertiesToAppend = lokiConfig.PropertiesToAppend ?? new List <string>();
            formatter.GlobalLabels       = lokiConfig.LogLabelProvider != null
            ? lokiConfig.LogLabelProvider.GetLabels()
            : new List <LokiLabel>();

            LokiCredentials credentials;

            if (string.IsNullOrWhiteSpace(lokiConfig.LokiUsername))
            {
                credentials = new NoAuthCredentials(lokiConfig.LokiUrl);
            }
            else
            {
                credentials = new BasicAuthCredentials(lokiConfig.LokiUrl, lokiConfig.LokiUsername, lokiConfig.LokiPassword);
            }

            var client = lokiConfig.HttpClient ?? new LokiHttpClient();

            if (client is LokiHttpClient c)
            {
                c.SetAuthCredentials(credentials);
            }
            return(serilogConfig.Http(LokiRouteBuilder.BuildPostUri(credentials.Url), batchFormatter: formatter, httpClient: client));
        }
Пример #2
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));
        }
Пример #3
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));
        }
        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));
        }