Ejemplo n.º 1
0
 public LokiLogHandler(string serverName, LokiCredentials credentials)
 {
     _sLogger = new LoggerConfiguration()
                .WriteTo.LokiHttp(credentials, new LogLabelProvider(serverName))
                .MinimumLevel.Debug()
                .CreateLogger();
 }
Ejemplo n.º 2
0
        public void RequestUriIsCorrect(string address)
        {
            // Arrange
            var credentials = new LokiCredentials(address);
            var log         = new LoggerConfiguration()
                              .MinimumLevel.Information()
                              .WriteTo.LokiHttp(credentials, httpClient: _client)
                              .CreateLogger();

            // Act
            log.Error("Something's wrong");
            log.Dispose();

            // Assert
            _client.RequestUri.ShouldBe(LokiRouteBuilder.BuildPostUri(credentials.Url));
        }
Ejemplo n.º 3
0
        public void NoAuthHeaderIsCorrect()
        {
            // Arrange
            var credentials = new LokiCredentials("http://test:80");
            var log         = new LoggerConfiguration()
                              .MinimumLevel.Information()
                              .WriteTo.LokiHttp(credentials, httpClient: _client)
                              .CreateLogger();

            // Act
            log.Error("Something's wrong");
            log.Dispose();

            // Assert
            _client.Client.DefaultRequestHeaders.Authorization.ShouldBeNull();
        }
Ejemplo n.º 4
0
    public void BasicAuthHeaderShouldBeCorrect()
    {
        var credentials = new LokiCredentials {
            Login = "******", Password = "******"
        };

        using var client = new TestLokiHttpClient();

        client.SetCredentials(credentials);

        var authorization = client.Client.DefaultRequestHeaders.Authorization;

        authorization.ShouldSatisfyAllConditions(
            () => authorization !.Scheme.ShouldBe("Basic"),
            () => authorization !.Parameter.ShouldBe("QmlsbHk6SGVycmluZ3Rvbg=="));
    }
Ejemplo n.º 5
0
        static void Main()
        {
            Exception ex;

            try
            {
                throw new Exception("Something went wrong, see StackTrace for more info");
            }
            catch (Exception e)
            {
                ex = e;
            }

            var credentials = new LokiCredentials("http://*****:*****@Position} in {Elapsed:000} ms.", position, elapsedMs);
            }

/*            log.Information("1# Logging {@Heartbeat:l} from {Computer:l}", "SomeValue", "SomeOtherValue");*/

/*            var position = new { Latitude = 25, Longitude = 134 };
 *          var exception = new {Message = ex.Message, StackTrace = ex.StackTrace};
 *          var elapsedMs = 34;*/

/*            log.Debug(@"Does this \""break\"" something?");
 *          log.Error("#2 {@Message}", exception);
 *          log.Information("3# Random message processed {@Position} in {Elapsed:000} ms.", position, elapsedMs);*/

            log.Dispose();
        }
Ejemplo n.º 6
0
        public void ContentMatchesApproved()
        {
            // Arrange
            var credentials = new LokiCredentials("http://*****:*****@"\d{1,2}\d{1,2}\d{2,4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{1,2}:\d{1,2}.\d{1,7}\+\d{2}:\d{2}", "<datetime>"));
        }
Ejemplo n.º 7
0
        public void BasicAuthHeaderShouldBeCorrect()
        {
            var credentials = new LokiCredentials {
                Login = "******", Password = "******"
            };
            var logger = new LoggerConfiguration()
                         .WriteTo.GrafanaLoki("http://loki:3100", credentials: credentials, httpClient: _client)
                         .CreateLogger();

            logger.Error("An error occured");
            logger.Dispose();

            var authorization = _client.Client.DefaultRequestHeaders.Authorization;

            authorization.ShouldSatisfyAllConditions(
                () => authorization.Scheme.ShouldBe("Basic"),
                () => authorization.Parameter.ShouldBe("QmlsbHk6SGVycmluZ3Rvbg=="));
        }
Ejemplo n.º 8
0
        public void BasicAuthHeaderIsCorrect()
        {
            // Arrange
            var credentials = new LokiCredentials("http://test:80", "Walter", "White");
            var log         = new LoggerConfiguration()
                              .MinimumLevel.Information()
                              .WriteTo.LokiHttp(credentials, httpClient: _client)
                              .CreateLogger();

            // Act
            log.Error("Something's wrong");
            log.Dispose();

            // Assert
            var auth = _client.Client.DefaultRequestHeaders.Authorization;

            auth.ShouldSatisfyAllConditions(
                () => auth.Scheme.ShouldBe("Basic"),
                () => auth.Parameter.ShouldBe("V2FsdGVyOldoaXRl")
                );
        }
 public LogLevelTests()
 {
     _client      = new TestHttpClient();
     _credentials = new LokiCredentials("http://test:80", "Walter", "White");
 }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
 public GlobalLabelsTests()
 {
     _client      = new TestHttpClient();
     _credentials = new LokiCredentials("http://test:80", "Walter", "White");
 }