protected override async Task Send(SyslogMessage syslogMessage)
        {
            if (!_udpClient.IsActive)
            {
                var logglyEndpointIp = Dns.GetHostEntry(LogglyConfig.Instance.Transport.EndpointHostname).AddressList[0];
                _udpClient.Connect(logglyEndpointIp, LogglyConfig.Instance.Transport.EndpointPort);
            }

            try
            {
                if (_udpClient.IsActive)
                {
                    var bytes = syslogMessage.GetBytes();
                    await _udpClient.SendAsync(bytes, bytes.Length).ConfigureAwait(false);
                }
                else
                {
                    LogglyException.Throw("Syslog client Socket is not connected.");
                }
            }
            finally
            {
                Close();
            }
        }
Exemple #2
0
        protected override async Task Send(SyslogMessage syslogMessage)
        {
            if (!_udpClient.IsActive)
            {
                var logglyEndpointIp = Dns.GetHostEntry(LogglyConfig.Instance.Transport.EndpointHostname).AddressList[0];
                _udpClient.Connect(logglyEndpointIp, LogglyConfig.Instance.Transport.EndpointPort);
            }

            try
            {
                if (_udpClient.IsActive)
                {
                    var bytes = syslogMessage.GetBytes();
                    await _udpClient.SendAsync(bytes, bytes.Length).ConfigureAwait(false);
                }
                else
                {
                    LogglyException.Throw("Syslog client Socket is not connected.");
                }
            }
            finally
            {
                Close();
            }
        }
        protected override async Task Send(SyslogMessage syslogMessage)
        {
            var client = new TcpClient();

            client.ConnectAsync(Hostname, LogglyConfig.Instance.Transport.EndpointPort).Wait();

            try
            {
                byte[] messageBytes  = syslogMessage.GetBytes();
                var    networkStream = await GetNetworkStream(client).ConfigureAwait(false);

                await networkStream.WriteAsync(messageBytes, 0, messageBytes.Length).ConfigureAwait(false);

                await networkStream.FlushAsync().ConfigureAwait(false);
            }
            catch (AuthenticationException e)
            {
                LogglyException.Throw(e, e.Message);
            }
            finally
            {
#if NET_STANDARD
                client.Dispose();
#else
                client.Close();
#endif
            }
        }
        protected override async Task Send(SyslogMessage syslogMessage)
        {
            var client = new TcpClient();
            client.ConnectAsync(Hostname, LogglyConfig.Instance.Transport.EndpointPort).Wait();

            try
            {
                byte[] messageBytes = syslogMessage.GetBytes();
                var networkStream = await GetNetworkStream(client).ConfigureAwait(false);
                await networkStream.WriteAsync(messageBytes, 0, messageBytes.Length).ConfigureAwait(false);
                await networkStream.FlushAsync().ConfigureAwait(false);
            }
            catch (AuthenticationException e)
            {
                LogglyException.Throw(e, e.Message);
            }
            finally
            {
#if NET_STANDARD
                client.Dispose();
#else
                client.Close();
#endif
            }

        }
Exemple #5
0
        protected override async Task Send(SyslogMessage syslogMessage)
        {
            await _semaphore.WaitAsync();

            try
            {
                if (_networkStream == null)
                {
                    _tcpClient = new TcpClient();
                    await _tcpClient.ConnectAsync(Hostname, LogglyConfig.Instance.Transport.EndpointPort).ConfigureAwait(false);

                    _networkStream = await GetNetworkStream(_tcpClient).ConfigureAwait(false);
                }

                byte[] messageBytes = syslogMessage.GetBytes();

                await _networkStream.WriteAsync(messageBytes, 0, messageBytes.Length).ConfigureAwait(false);

                await _networkStream.FlushAsync().ConfigureAwait(false);
            }
            catch (AuthenticationException e)
            {
                LogglyException.Throw(e, e.Message);
            }
            catch (IOException ioException)
            {
#if NET_STANDARD
                _tcpClient?.Dispose();
#else
                _tcpClient?.Close();
#endif
                _networkStream = null;
                LogglyException.Throw(ioException, ioException.Message);
            }
            catch (ObjectDisposedException disposedException)
            {
                _networkStream = null;
                LogglyException.Throw(disposedException, disposedException.Message);
            }
            finally
            {
                _semaphore.Release();
            }
        }
Exemple #6
0
        protected override void Send(SyslogMessage syslogMessage)
        {
            var client = new TcpClient(Hostname, LogglyConfig.Instance.Transport.EndpointPort);

            try
            {
                byte[] messageBytes  = syslogMessage.GetBytes();
                var    networkStream = GetNetworkStream(client);
                networkStream.Write(messageBytes, 0, messageBytes.Length);
                networkStream.Flush();
            }
            catch (AuthenticationException e)
            {
                LogglyException.Throw(e, e.Message);
            }
            finally
            {
                client.Close();
            }
        }
        protected override void Send(SyslogMessage syslogMessage)
        {
            var client = new TcpClient(Hostname, LogglyConfig.Instance.Transport.EndpointPort);

            try
            {
                byte[] messageBytes = syslogMessage.GetBytes();
                var networkStream = GetNetworkStream(client);
                networkStream.Write(messageBytes, 0, messageBytes.Length);
                networkStream.Flush();
            }
            catch (AuthenticationException e)
            {
                LogglyException.Throw(e, e.Message);
            }
            finally
            {
                client.Close();
            }
        }
 protected override async Task Send(SyslogMessage syslogMessage)
 {
     try
     {
         var hostEntry = Dns.GetHostEntryAsync(LogglyConfig.Instance.Transport.EndpointHostname).Result;
         var logglyEndpointIp = hostEntry.AddressList[0];
         var bytes = syslogMessage.GetBytes();
         await _udpClient.SendAsync(
             bytes,
             bytes.Length,
             new IPEndPoint(logglyEndpointIp, LogglyConfig.Instance.Transport.EndpointPort)).ConfigureAwait(false);
     }
     catch (Exception ex)
     {
         LogglyException.Throw(ex, "Error when sending data using Udp client.");
     }
     finally
     {
         Close();
     }
 }
Exemple #9
0
 protected override async Task Send(SyslogMessage syslogMessage)
 {
     try
     {
         var hostEntry        = Dns.GetHostEntryAsync(LogglyConfig.Instance.Transport.EndpointHostname).Result;
         var logglyEndpointIp = hostEntry.AddressList[0];
         var bytes            = syslogMessage.GetBytes();
         await _udpClient.SendAsync(
             bytes,
             bytes.Length,
             new IPEndPoint(logglyEndpointIp, LogglyConfig.Instance.Transport.EndpointPort)).ConfigureAwait(false);
     }
     catch (Exception ex)
     {
         LogglyException.Throw(ex, "Error when sending data using Udp client.");
     }
     finally
     {
         Close();
     }
 }