static void Main(string[] args) { SeverityFilter warning_filter = new SeverityFilter() { comparison = ComparisonOperator.geq, severity = SyslogSeverity.Warning }; Console.WriteLine("This program is going to listen for all messages with severity >= Warning."); Console.WriteLine("All received messages will be written on this console in their native format."); Console.WriteLine(); Console.WriteLine("You must start Logbus daemon prior to running this program."); Console.WriteLine("Please press ENTER when you are sure that Logbus daemon is already running..."); Console.ReadLine(); Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress); try { logclient = ClientHelper.CreateUnreliableClient(warning_filter); logclient.MessageReceived += new EventHandler <SyslogMessageEventArgs>(logclient_MessageReceived); logclient.Start(); Console.WriteLine("Listener is started. Press CTRL+C to exit when you are finished"); Thread.Sleep(Timeout.Infinite); } catch (Exception ex) { Console.WriteLine("Something went wrong..."); Console.WriteLine(ex); Environment.Exit(1); } }
public void TestTlsClient() { _success = new AutoResetEvent(false); using (ILogBus logbus = LogbusSingletonHelper.Instance) { logbus.Start(); using (ILogClient client = ClientHelper.CreateReliableClient(new TrueFilter())) { client.Start(); client.MessageReceived += client_MessageReceived; ILog logger = LoggerHelper.GetLogger(); logger.Notice("Hello K.I.T.T.!"); Assert.IsTrue(_success.WaitOne(10000)); } } }
static void Main(string[] args) { Console.WriteLine("This program monitors only heartbeats coming from any entity in the system."); Console.WriteLine("Press CTRL+C when you are finished."); PropertyFilter idFilt = new PropertyFilter { comparison = ComparisonOperator.eq, propertyName = Property.MessageID, value = "HEARTBEAT" }; SeverityFilter debugFilter = new SeverityFilter { comparison = ComparisonOperator.eq, severity = SyslogSeverity.Debug }; using (ILogClient client = ClientHelper.CreateUnreliableClient(idFilt & debugFilter)) { client.MessageReceived += client_MessageReceived; client.Start(); Thread.Sleep(Timeout.Infinite); } }
private static void Run(int timeout) { _messagesRcvd = new BitArray(_expected, false); _received = 0; string pid = Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture); ILogCollector server = CollectorHelper.CreateCollector(); string host = Dns.GetHostName(); PropertyFilter hostFilter = new PropertyFilter { comparison = ComparisonOperator.eq, value = host, propertyName = Property.Host }; FacilityEqualsFilter facFilter = new FacilityEqualsFilter { facility = SyslogFacility.Local4 }; PropertyFilter pidFilter = new PropertyFilter { comparison = ComparisonOperator.eq, value = pid, propertyName = Property.ProcessID }; PropertyFilter idFilter = new PropertyFilter { value = "BENCH", comparison = ComparisonOperator.eq, propertyName = Property.MessageID }; SeverityFilter sevFilter = new SeverityFilter { comparison = ComparisonOperator.eq, severity = SyslogSeverity.Notice }; using (ILogClient client = ClientHelper.CreateReliableClient(hostFilter & pidFilter & idFilter & sevFilter & facFilter)) { client.MessageReceived += client_MessageReceived; client.Start(); for (int i = 0; i < _expected; i++) { if (timeout > 0) { Nanosleep(timeout); } SyslogMessage message = new SyslogMessage { Timestamp = DateTime.Now, Facility = SyslogFacility.Local4, Severity = SyslogSeverity.Notice, Host = host, ProcessID = pid, MessageId = "BENCH", Text = i.ToString() }; server.SubmitMessage(message); } silenceTimer = new Timer(state => Stop.Set(), null, 40000, Timeout.Infinite); Console.WriteLine("Waiting up to 30 seconds after last message received..."); Stop.WaitOne(); } if (_expected == _received) { Console.WriteLine("Received all messaged"); } else { Console.WriteLine("Lost {0} messages", _expected - _received); } }
static void Main(string[] args) { bool reliable = args != null && args.Length > 0 && args[0] == "--reliable"; Console.CancelKeyPress += Console_CancelKeyPress; Console.WriteLine("This program periodically measures the RTT for log messages sent by here"); if (!reliable) { Console.WriteLine("Going in unreliable mode. Messages are subject to loss."); Console.WriteLine("Use the --reliable switch to go into reliable mode, where messages don't get lost."); } else { Console.WriteLine("Reliable mode activated. No messages will be lost because of the network."); } PropertyFilter hostFilter = new PropertyFilter { comparison = ComparisonOperator.eq, value = Dns.GetHostName(), propertyName = Property.Host }; PropertyFilter pidFilter = new PropertyFilter { comparison = ComparisonOperator.eq, value = Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), propertyName = Property.ProcessID }; PropertyFilter idFilter = new PropertyFilter { value = "RTT", comparison = ComparisonOperator.eq, propertyName = Property.MessageID }; _target = CollectorHelper.CreateCollector((reliable) ? "tls" : "udp"); FilterBase filter = hostFilter & pidFilter & idFilter; _source = (reliable) ? ClientHelper.CreateReliableClient(filter) : ClientHelper.CreateUnreliableClient(filter); _log = LoggerHelper.GetLogger("Logfile"); _source.MessageReceived += source_MessageReceived; _source.Start(); while (true) { _id++; DateTime curTimestamp = DateTime.UtcNow; double millis = (curTimestamp - DateTime.Today).TotalMilliseconds; string text = _id.ToString(CultureInfo.InvariantCulture) + "_" + millis.ToString(CultureInfo.InvariantCulture); SyslogMessage message = new SyslogMessage(SyslogFacility.Local3, SyslogSeverity.Notice, text) { MessageId = "RTT" }; _target.SubmitMessage(message); if (!_ar.WaitOne(10000)) { Console.WriteLine("RTT sent at {0} lost", curTimestamp); _log.Warning("RTT sent at {0} lost", curTimestamp); continue; } Thread.Sleep(3000); } }