コード例 #1
0
        public void Logging_LinesLogTest()
        {
            IActionLinesLog log = new LinesLog(NullLogWriter.Instance);

            log.WriteAsync(MessageCategory.Error, "message1").Wait();
            log.WriteLineAsync(MessageCategory.Error, " message2").Wait();
            log.WriteFormatAsync(MessageCategory.Error, "message3 {0}\r\n", 1).Wait();
            log.WriteLineAsync(MessageCategory.Error, "message4").Wait();

            log.Content.Should().Be("message1 message2\r\nmessage3 1\r\nmessage4\r\n");
            log.Lines.Should().Equal("message1 message2", "message3 1", "message4", string.Empty);
        }
コード例 #2
0
        public async Task Run(CancellationToken ct = default(CancellationToken))
        {
            TaskUtilities.AssertIsOnBackgroundThread();

            if (_runTask != null)
            {
                throw new InvalidOperationException("This host is already running.");
            }

            ct = CancellationTokenSource.CreateLinkedTokenSource(ct, _cts.Token).Token;

            try {
                _runTask = RunWorker(ct);
                await _runTask;
            } catch (OperationCanceledException) when(ct.IsCancellationRequested)
            {
                // Expected cancellation, do not propagate, just exit process
            } catch (MessageTransportException ex) when(ct.IsCancellationRequested)
            {
                // Network errors during cancellation are expected, but should not be exposed to clients.
                throw new OperationCanceledException(new OperationCanceledException().Message, ex);
            } catch (Exception ex) {
                var message = "Exception in RHost run loop:\n" + ex;
                _log.WriteLineAsync(MessageCategory.Error, message).DoNotWait();
                Debug.Fail(message);
                throw;
            } finally {
                _requests.Clear();
            }
        }