public void AddLogRequest_InitialiseLogStream_ShouldBeCalledINoLogStream()
        {
            //arrange
            var cloudwatchClient = InitialiseClient();

            var logstream = Logstream + Guid.NewGuid();

            var cloudwatvhLogClient = new CloudWatchLogsClientWrapper(
                cloudwatchClient,
                LogGroup,
                logstream);

            var logevents = Builder <InputLogEvent>
                            .CreateListOfSize(20)
                            .All()
                            .With(x => x.Timestamp = DateTime.Now.AddDays(-1))
                            .Build()
                            .ToList();

            //act
            try
            {
                cloudwatvhLogClient.AddLogRequest(logevents);
            }
            catch (ApplicationException ex)
            {
                if (ex.Message == "LogStream doesn't exist")
                {
                    //assert
                    Assert.Pass();
                }
            }
        }
        public void AddLogRequest_AllShouldbeCommited()
        {
            //arrange
            var cloudwatchClient = InitialiseClient();

            var logstream = Logstream + Guid.NewGuid();

            var cloudwatvhLogClient = new CloudWatchLogsClientWrapper(
                cloudwatchClient,
                LogGroup,
                logstream);

            cloudwatvhLogClient.InitialiseLogStream();

            var logevents = Builder <InputLogEvent>
                            .CreateListOfSize(20)
                            .All()
                            .With(x => x.Timestamp = DateTime.Now.AddDays(-1))
                            .Build()
                            .ToList();

            //act
            cloudwatvhLogClient.AddLogRequest(logevents);

            Thread.Sleep(2000);

            var results = cloudwatchClient.GetLogEvents(new GetLogEventsRequest(
                                                            LogGroup,
                                                            logstream));

            //assert
            results.Events.Count.Should().Equal(20);
            results.Events.All(x => string.IsNullOrEmpty(x.Message));
            results.Events.All(x => x.Timestamp != new DateTime());
        }
        protected override void SendBuffer(LoggingEvent[] events)
        {
            var rs = ProcessEvents(events);

            var requests = Assemble(rs);

            foreach (var putMetricDataRequest in requests)
            {
                _client.AddLogRequest(putMetricDataRequest);
            }
        }
Beispiel #4
0
        protected override void SendBuffer(LoggingEvent[] events)
        {
            var rs = events.SelectMany(e => _eventProcessor.ProcessEvent(e, RenderLoggingEvent(e)).Select(r => r));

            var requests = Assemble(rs);

            foreach (var putMetricDataRequest in requests)
            {
                _client.AddLogRequest(putMetricDataRequest);
            }
        }
        public void AddLogRequest_Verify()
        {
            //arrange
            var container = new AutoMoqer();

            var amazonclientMock = container.GetMock <IAmazonCloudWatchLogs>();

            amazonclientMock.Setup(
                x => x.DescribeLogStreams(
                    It.IsAny <DescribeLogStreamsRequest>()
                    )
                ).Returns(new DescribeLogStreamsResponse
            {
                LogStreams = new List <LogStream>
                {
                    new LogStream
                    {
                        LogStreamName = Logstream
                    }
                }
            });

            amazonclientMock.Setup(x => x.PutLogEvents(It.IsAny <PutLogEventsRequest>()))
            .Returns(new PutLogEventsResponse());

            var target = new CloudWatchLogsClientWrapper(amazonclientMock.Object, LogGroup, Logstream);

            var logEvents = new List <InputLogEvent>()
            {
                new InputLogEvent
                {
                    Message   = "TestMessage",
                    Timestamp = DateTime.UtcNow
                }
            };

            //act
            target.AddLogRequest(logEvents);

            //assert
            amazonclientMock.Verify(x => x.PutLogEvents(
                                        It.Is <PutLogEventsRequest>(y =>
                                                                    y.LogGroupName == LogGroup &&
                                                                    y.LogStreamName == Logstream &&
                                                                    y.LogEvents.Single().Message == logEvents.Single().Message&&
                                                                    y.LogEvents.Single().Timestamp == logEvents.Single().Timestamp
                                                                    ))
                                    , Times.Once()
                                    );
        }
Beispiel #6
0
        protected override void Append(LoggingEvent loggingEvent)
        {
            LogLog.Debug(_declaringType, "Appending");

            if (!EventRateLimiter.Request(loggingEvent.TimeStamp))
            {
                LogLog.Debug(_declaringType, "Appending denied due to event limiter saturated.");
                return;
            }

            var logDatum = _eventProcessor.ProcessEvent(loggingEvent, RenderLoggingEvent(loggingEvent)).Single();

            _client.AddLogRequest(new PutLogEventsRequest(logDatum.GroupName, logDatum.StreamName, new[] { new InputLogEvent
                                                                                                           {
                                                                                                               Timestamp = logDatum.Timestamp.Value.ToUniversalTime(),
                                                                                                               Message   = logDatum.Message
                                                                                                           } }.ToList()));
        }