Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            try
            {
                var options = new Options();
                if (new CommandLineParser().ParseArguments(args, options))
                {
                    // string exceptionMessage = CreateExceptionMessageLevel1();

                    ISyslogMessageSerializer serializer = options.SyslogVersion == "5424"
                        ? (ISyslogMessageSerializer)new SyslogRfc5424MessageSerializer()
                        : new SyslogRfc3164MessageSerializer();

                    ISyslogMessageSender sender = options.NetworkProtocol == "tcp"
                        ? (ISyslogMessageSender)new SyslogEncryptedTcpSender(options.SyslogServerHostname, options.SyslogServerPort)
                        : new SyslogUdpSender(options.SyslogServerHostname, options.SyslogServerPort);

                    SyslogMessage msg1 = CreateSyslogMessage(options);
                    sender.Send(msg1, serializer);
                    Console.WriteLine("Sent message 1");

                    Thread.Sleep(5000);

                    SyslogMessage msg2 = CreateSyslogMessage(options);
                    sender.Send(msg2, serializer);
                    Console.WriteLine("Sent message 2");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex);
            }
        }
Ejemplo n.º 2
0
		private static SyslogMessage CreateSyslogMessage(Options options)
		{
			return new SyslogMessage(
				DateTimeOffset.Now,
				Facility.UserLevelMessages,
				Severity.Error,
				options.LocalHostName ?? Environment.MachineName,
				options.AppName,
				options.ProcId,
				options.MsgType,
				options.Message ?? "Test message at " + DateTime.Now);
		}