コード例 #1
0
        private static LoggerConfiguration LokiHttpImpl(this LoggerSinkConfiguration serilogConfig, LokiSinkConfiguration lokiConfig)
        {
            var credentials = string.IsNullOrWhiteSpace(lokiConfig.LokiUsername)
                ? (LokiCredentials) new NoAuthCredentials(lokiConfig.LokiUrl)
                : new BasicAuthCredentials(lokiConfig.LokiUrl, lokiConfig.LokiUsername, lokiConfig.LokiPassword);

            return(LokiHttpImpl(serilogConfig, credentials, lokiConfig.LogLabelProvider, lokiConfig.HttpClient, lokiConfig.OutputTemplate, lokiConfig.FormatProvider));
        }
コード例 #2
0
        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));
        }