public static LoggerConfiguration TitanLoki(this LoggerSinkConfiguration sinkConfiguration, LokiCredentials credentials,
                                                    ILogLabelProvider logLabelProvider, IHttpClient httpClient, LogEventLevel logLevelRestriction,
                                                    int batchPostingLimit, TimeSpan period, int queueLimit, bool dynamicLevel)
        {
            BatchFormatter formatter = logLabelProvider != null
                                           ? new BatchFormatter(logLabelProvider.GetLabels())
                                           : new BatchFormatter();

            IHttpClient client = httpClient ?? new LokiHttpClient();

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

            if (dynamicLevel)
            {
                return(sinkConfiguration.Http(LokiRouteBuilder.BuildPostUri(credentials.Url), batchFormatter: formatter, httpClient: client,
                                              batchPostingLimit: batchPostingLimit, period: period,
                                              queueLimit: queueLimit));
            }

            return(sinkConfiguration.Http(LokiRouteBuilder.BuildPostUri(credentials.Url), batchFormatter: formatter, httpClient: client,
                                          restrictedToMinimumLevel: logLevelRestriction, batchPostingLimit: batchPostingLimit, period: period,
                                          queueLimit: queueLimit));
        }
Beispiel #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));
        }
Beispiel #3
0
 public LokigRpcClient(
     string grpcEndpoint,
     ILogLabelProvider globalLabelsProvider = null,
     int?queueLimit         = 2,
     int?batchSizeLimit     = 1000,
     TimeSpan?period        = null,
     bool stackTraceAsLabel = false
     ) : this(grpcEndpoint, globalLabelsProvider, queueLimit ?? int.MaxValue, batchSizeLimit ?? 1000,
              period ?? TimeSpan.FromSeconds(2), stackTraceAsLabel)
 {
 }
 /// <summary>
 /// Adds Grafana Loki gRPC sink.
 /// </summary>
 /// <param name="sinkLoggerConfiguration"></param>
 /// <param name="grpcEndpoint">host:port for gRPC</param>
 /// <param name="labelProvider">Custom ILogLabelProvider implementation</param>
 /// <param name="restrictedToMinimumLevel">Minimum level for events passing through the sink</param>
 /// <param name="stackTraceAsLabel">Indicates if exception stacktrace should be sent as a label</param>
 /// <returns></returns>
 public static LoggerConfiguration LokigRPC(
     this LoggerSinkConfiguration sinkLoggerConfiguration,
     string grpcEndpoint, ILogLabelProvider labelProvider = null,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
     bool stackTraceAsLabel = false)
 {
     return(sinkLoggerConfiguration.Sink(
                new LokigRpcClient(
                    grpcEndpoint,
                    labelProvider,
                    period: TimeSpan.FromSeconds(2),
                    queueLimit: int.MaxValue,
                    stackTraceAsLabel: stackTraceAsLabel
                    ), restrictedToMinimumLevel
                ));
 }
Beispiel #5
0
        public LokigRpcClient(
            string grpcEndpoint,
            ILogLabelProvider globalLabelsProvider,
            int queueLimit,
            int batchSizeLimit,
            TimeSpan period,
            bool stackTraceAsLabel = false
            ) : base(batchSizeLimit, period, queueLimit)
        {
            if (string.IsNullOrEmpty(grpcEndpoint))
            {
                throw new ArgumentNullException(nameof(grpcEndpoint));
            }

            _stackTraceAsLabel    = stackTraceAsLabel;
            _globalLabelsProvider = globalLabelsProvider;
            _client = new Pusher.PusherClient(new Channel(grpcEndpoint, ChannelCredentials.Insecure));
        }
 /// <summary>
 /// Adds Grafana Loki gRPC sink.
 /// </summary>
 /// <param name="sinkLoggerConfiguration"></param>
 /// <param name="grpcEndpoint">host:port for gRPC</param>
 /// <param name="labelProvider">Custom ILogLabelProvider implementation</param>
 /// <param name="period">The time to wait between checking for event batches. Default value is 2 seconds.</param>
 /// <param name="queueLimit">The maximum number of events stored in the queue in memory, waiting to be posted over the network. Default value is infinitely.</param>
 /// <param name="batchSizeLimit">The maximum number of events to post in a single batch. Default value is 1000.</param>
 /// <param name="restrictedToMinimumLevel">Minimum level for events passing through the sink</param>
 /// <param name="stackTraceAsLabel">Indicates if exception stacktrace should be sent as a label</param>
 /// <returns></returns>
 public static LoggerConfiguration LokigRPC(
     this LoggerSinkConfiguration sinkLoggerConfiguration,
     string grpcEndpoint,
     ILogLabelProvider labelProvider,
     TimeSpan period,
     int queueLimit,
     int batchSizeLimit,
     LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
     bool stackTraceAsLabel = false
     )
 {
     return(sinkLoggerConfiguration.Sink(
                new LokigRpcClient(
                    grpcEndpoint,
                    labelProvider,
                    queueLimit,
                    batchSizeLimit,
                    period,
                    stackTraceAsLabel
                    ), restrictedToMinimumLevel
                ));
 }
Beispiel #7
0
 public static LoggerConfiguration LokiHttp(this LoggerSinkConfiguration sinkConfiguration, LokiCredentials credentials, ILogLabelProvider labelProvider = null, LokiHttpClient httpClient = null)
 => LokiHttpImpl(sinkConfiguration, credentials, labelProvider, httpClient);
Beispiel #8
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));
        }
Beispiel #9
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);
 public LokiBatchFormatter(IList <LokiLabel> globalLabels)
 {
     this.LogLabelProvider = new DefaultLogLabelProvider(globalLabels);
 }
 public LokiBatchFormatter(ILogLabelProvider logLabelProvider)
 {
     this.LogLabelProvider = logLabelProvider;
 }
 public LokiBatchFormatter()
 {
     this.LogLabelProvider = new DefaultLogLabelProvider();
 }
        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));
        }
 public static LoggerConfiguration LokiHttp(this LoggerSinkConfiguration sinkConfiguration, string serverUrl, string username, string password, ILogLabelProvider labelProvider = null, LokiHttpClient httpClient = null, string outputTemplate = LokiSinkConfiguration.DefaultTemplate, IFormatProvider formatProvider = null)
 => LokiHttpImpl(sinkConfiguration, new BasicAuthCredentials(serverUrl, username, password), labelProvider, httpClient, outputTemplate, formatProvider);