Example #1
0
        private async Task EnsureVirtualConnectionClientCreated()
        {
            // Asynchronous equivalent to a 'lock(...) { ... }'
            await _connectionCreationSemaphore.WaitAsync();

            try
            {
                if (_virtualConnectionClient == null)
                {
                    _physicalConnection = StreamConnection.Create();

                    var connection = await _physicalConnection.Open(_socketAddress);

                    _virtualConnectionClient          = new VirtualConnectionClient(connection);
                    _virtualConnectionClient.OnError += (ex) =>
                    {
                        // This callback is fired only if there's a protocol-level failure (e.g., child process disconnected
                        // unexpectedly). It does *not* fire when RPC calls return errors. Since there's been a protocol-level
                        // failure, this Node instance is no longer usable and should be discarded.
                        _connectionHasFailed = true;

                        OutputLogger.LogError(0, ex, ex.Message);
                    };
                }
            }
            finally
            {
                _connectionCreationSemaphore.Release();
            }
        }
Example #2
0
        public void AssertThat_Exceptions_CanBeConvertedToJson()
        {
            ILogOutputStream <Object> outputStream = JsonLogOutput.CreateLogOutputStream(
                new GenericOutputStream <String>(log => _testOutputHelper.WriteLine(log))
                );

            using var logger = new OutputLogger(outputStream);

            try
            {
                throw new Exception("test");
            }
            catch (Exception ex)
            {
                logger.LogError(new EventId(0, ""), new { }, ex);
            }
        }