public void EventsAreFormattedIntoCompactJsonPayloads()
        {
            var evt       = Some.LogEvent("Hello, {Name}!", "Alice");
            var formatter = new ConstrainedBufferedFormatter(null);
            var json      = new StringWriter();

            formatter.Format(evt, json);
            Assert.Contains("Name\":\"Alice", json.ToString());
        }
        public void PlaceholdersAreLoggedWhenCompactJsonRenderingFails()
        {
            var evt       = Some.LogEvent(new NastyException(), "Hello, {Name}!", "Alice");
            var formatter = new ConstrainedBufferedFormatter(null);
            var json      = new StringWriter();

            formatter.Format(evt, json);
            var jsonString = json.ToString();

            Assert.Contains("could not be formatted", jsonString);
            Assert.Contains("OriginalMessageTemplate\":\"Hello, ", jsonString);
        }
        public void PlaceholdersAreLoggedWhenTheEventSizeLimitIsExceeded()
        {
            var evt       = Some.LogEvent("Hello, {Name}!", new string('a', 10000));
            var formatter = new ConstrainedBufferedFormatter(2000);
            var json      = new StringWriter();

            formatter.Format(evt, json);
            var jsonString = json.ToString();

            Assert.Contains("exceeds the body size limit", jsonString);
            Assert.Contains("\"EventBodySample\"", jsonString);
            Assert.Contains("aaaaa", jsonString);
        }
        public async Task EmitBatchAsync(IEnumerable <LogEvent> events)
        {
            _nextRequiredLevelCheckUtc = DateTime.UtcNow.Add(RequiredLevelCheckInterval);

            var payload = new StringWriter();

            foreach (var evt in events)
            {
                _formatter.Format(evt, payload);
            }

            var clefPayload = payload.ToString();

            var minimumAcceptedLevel = await _ingestionApi.IngestAsync(clefPayload);

            _controlledSwitch.Update(minimumAcceptedLevel);
        }