예제 #1
0
        public async Task Logging_TimedBuffer()
        {
            // To ensure this test does not take too long and to not wait for the buffer to
            // flush itself we use custom polling to check for the initial check that no
            // entries exist.
            var      quickPolling = new LogEntryPolling(TimeSpan.FromSeconds(10));
            string   testId       = Utils.GetTestId();
            DateTime startTime    = DateTime.UtcNow;

            var builder = new WebHostBuilder().UseStartup <TimedBufferWarningLoggerTestApplication>();

            using (TestServer server = new TestServer(builder))
                using (var client = server.CreateClient())
                {
                    await client.GetAsync($"/Main/Warning/{testId}");

                    await client.GetAsync($"/Main/Error/{testId}");

                    var noResults = quickPolling.GetEntries(startTime, testId, 0, LogSeverity.Warning);
                    Assert.Empty(noResults);

                    await client.GetAsync($"/Main/Error/{testId}");

                    await client.GetAsync($"/Main/Critical/{testId}");

                    Thread.Sleep(TimeSpan.FromSeconds(20));

                    var results = _polling.GetEntries(startTime, testId, 4, LogSeverity.Warning);
                    Assert.Equal(4, results.Count());
                    Assert.NotNull(results.FirstOrDefault(l => l.Severity == LogSeverity.Warning));
                    Assert.Equal(2, results.Count(l => l.Severity == LogSeverity.Error));
                    Assert.NotNull(results.FirstOrDefault(l => l.Severity == LogSeverity.Critical));
                }
        }
예제 #2
0
        private static async Task TestLogging(string testId, DateTime startTime, HttpClient client)
        {
            var polling = new LogEntryPolling(TimeSpan.FromSeconds(60));
            await client.GetAsync($"/Main/Warning/{testId}");

            var results = polling.GetEntries(startTime, testId, 1, LogSeverity.Warning);

            Assert.Single(results);
        }
예제 #3
0
        public async Task Logging_SizedBufferNoLogs()
        {
            string   testId    = Utils.GetTestId();
            DateTime startTime = DateTime.UtcNow;

            var builder = new WebHostBuilder().UseStartup <SizedBufferErrorLoggerTestApplication>();

            using (TestServer server = new TestServer(builder))
                using (var client = server.CreateClient())
                {
                    await client.GetAsync($"/Main/Warning/{testId}");

                    await client.GetAsync($"/Main/Error/{testId}");

                    await client.GetAsync($"/Main/Critical/{testId}");

                    // No entries should be found as not enough entries were created to
                    // flush the buffer.
                    Assert.Empty(_polling.GetEntries(startTime, testId, 0, LogSeverity.Default));
                }
        }
        internal static void PollAndVerifyLog(DateTime startTime, string testId)
        {
            var results = s_polling.GetEntries(startTime, testId, 1, LogSeverity.Info);

            results = from result in results
                      where result.JsonPayload?.Fields["log_name"]?.StringValue?.Equals(typeof(LoggingSamplesController).FullName) ?? false
                      select result;

            var logEntry = results.Single();

            Assert.Equal(LogSeverity.Info, logEntry.Severity);
            Assert.Contains(testId, logEntry.JsonPayload?.Fields["message"]?.StringValue);
        }
        private static async Task TestLogging(string testId, DateTime startTime, HttpClient client)
        {
            var polling = new LogEntryPolling(TimeSpan.FromSeconds(60));
            await client.GetAsync($"/Main/Warning/{testId}");

            var results = polling.GetEntries(startTime, testId, 1, LogSeverity.Warning);

            Assert.Single(results);
            var result = results.Single();

            Assert.Single(result.Labels);
            var label = result.Labels.Single();

            Assert.Equal("trace_identifier", label.Key);
            Assert.NotEmpty(label.Value);
        }