コード例 #1
0
        private void WaitForGelfInput(GelfLoggingSink sink)
        {
            var diagnosticEvent = new DiagnosticEventBuilder(sink, DiagnosticEventType.ComponentInitialization)
            {
                Detail = "[Unit Test] Waiting for GELF input to start (" + GetType().Name + ")"
            }.Build();

            using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)))
            {
                while (!cts.IsCancellationRequested)
                {
                    try
                    {
                        sink.Consume(diagnosticEvent);
                        return;
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        Task.Delay(TimeSpan.FromSeconds(1)).Wait(cts.Token);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
コード例 #2
0
        public async Task MessagesCanBeHandledConcurrently()
        {
            const int count = 10;
            var       tasks = Enumerable
                              .Range(0, count)
                              .Select(i => Task.Run(() =>
            {
                var messageNumber = i + 1;
                var message       = GenerateMessage();
                var detail        = "Concurrent message (" + messageNumber + " of " + count + ")";
                var @event        = GenerateDiagnosticEvent(this, TestExecuted, message, detail);

                GelfLoggingSink.Consume(@event);
            }));

            await Task.WhenAll(tasks);
        }