/// <summary>
        /// Adds a sink that sends log events as UDP packages over the network.
        /// </summary>
        /// <param name="sinkConfiguration">Logger sink configuration.</param>
        /// <param name="remoteAddress">
        /// The <see cref="IPAddress"/> of the remote host or multicast group to which the UDP
        /// client should sent the logging event.
        /// </param>
        /// <param name="remotePort">
        /// The TCP port of the remote host or multicast group to which the UDP client should sent
        /// the logging event.
        /// </param>
        /// <param name="formatter">
        /// Controls the rendering of log events into text, for example to log JSON. To control
        /// plain text formatting, use the overload that accepts an output template.
        /// </param>
        /// <param name="localPort">
        /// The TCP port from which the UDP client will communicate. The default is 0 and will
        /// cause the UDP client not to bind to a local port.
        /// </param>
        /// <param name="restrictedToMinimumLevel">
        /// The minimum level for events passed through the sink. The default is
        /// <see cref="LevelAlias.Minimum"/>.
        /// </param>
        /// <param name="levelSwitch">
        /// A switch allowing the pass-through minimum level to be changed at runtime.
        /// </param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        public static LoggerConfiguration Udp(
            this LoggerSinkConfiguration sinkConfiguration,
            IPAddress remoteAddress,
            int remotePort,
            ITextFormatter formatter,
            int localPort = 0,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            LoggingLevelSwitch levelSwitch         = null)
        {
            if (sinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(sinkConfiguration));
            }

            try
            {
                var client = UdpClientFactory.Create(localPort, remoteAddress);
                var sink   = new UdpSink(client, remoteAddress, remotePort, formatter);
                return(sinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch));
            }
            catch (Exception e)
            {
                SelfLog.WriteLine("Unable to create UDP sink: {0}", e);
                return(sinkConfiguration.Sink(new NullSink(), LevelAlias.Maximum, null));
            }
        }
        public void CreateClientForeachInterface_InstancesReturned()
        {
            // Arrange
            var factory = new UdpClientFactory();

            // Act
            var clients = factory.CreateClientForeachInterface();

            // Assert
            clients.Should().HaveCountGreaterOrEqualTo(1);
            clients.Should().AllBeOfType <OnvifUdpClient> ();
        }
        public void CreateClient_WithEndpoint_InstanceReturned()
        {
            // Arrange
            var factory  = new UdpClientFactory();
            var endpoint = new IPEndPoint(IPAddress.Loopback, 0);

            // Act
            var client = factory.CreateClient(endpoint);

            // Assert
            client.Should().NotBeNull();
            client.Should().BeOfType <OnvifUdpClient> ();
        }
Exemplo n.º 4
0
        private DefaultProxy createProxy()
        {
            var dialog = new DefaultProxyDialog();

            dialog.ShowDialog();
            if (dialog.DialogResult == DialogResult.OK)
            {
                var clFactory = new UdpClientFactory(dialog.UdpClientFactorySettings);
                var srv       = new UdpServer(dialog.UdpServerSettings);
                return(new DefaultProxy(new DefaultProxySettings {
                    Server = srv, ClientFactory = clFactory
                }));
            }
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a sink that sends log events as UDP packages over the network.
        /// </summary>
        /// <param name="sinkConfiguration">Logger sink configuration.</param>
        /// <param name="remoteAddress">
        /// The <see cref="IPAddress"/> of the remote host or multicast group to which the UDP
        /// client should sent the logging event.
        /// </param>
        /// <param name="remotePort">
        /// The TCP port of the remote host or multicast group to which the UDP client should sent
        /// the logging event.
        /// </param>
        /// <param name="formatter">
        /// Controls the rendering of log events into text, for example to log JSON. To control
        /// plain text formatting, use the overload that accepts an output template.
        /// </param>
        /// <param name="localPort">
        /// The TCP port from which the UDP client will communicate. The default is 0 and will
        /// cause the UDP client not to bind to a local port.
        /// </param>
        /// <param name="restrictedToMinimumLevel">
        /// The minimum level for events passed through the sink. The default is
        /// <see cref="LevelAlias.Minimum"/>.
        /// </param>
        /// <param name="levelSwitch">
        /// A switch allowing the pass-through minimum level to be changed at runtime.
        /// </param>
        /// <returns>Logger configuration, allowing configuration to continue.</returns>
        public static LoggerConfiguration Udp(
            this LoggerSinkConfiguration sinkConfiguration,
            IPAddress remoteAddress,
            int remotePort,
            ITextFormatter formatter,
            int localPort = 0,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
            LoggingLevelSwitch levelSwitch         = null)
        {
            if (sinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(sinkConfiguration));
            }

            var client = UdpClientFactory.Create(localPort, remoteAddress);
            var sink   = new UdpSink(client, remoteAddress, remotePort, formatter);

            return(sinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch));
        }