public static void Main(string[] args)
 {
     using (Syslog.Client c = new Syslog.Client(IPAddress.Parse("127.0.0.1"), 514, Syslog.Facility.Local6, Syslog.Level.Warning, "Test.Application"))
     {
         c.Send("This is a test of the syslog client code.");
     }
 }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Sending test message to localhost Syslog server...");

            using (Syslog.Client c = new Syslog.Client(IPAddress.Parse("172.17.82.26"), 514, Syslog.Facility.Local6, Syslog.Level.Warning, "Test.Application Test"))
            {
                c.Send("This is a test of the syslog client code. Привет");

                c.Send(new Syslog.Rfc3164Message(Syslog.Facility.Local6, Syslog.Level.Warning, "Test.Application test", "This is a test of the syslog client code. Привет")
                {
                    PID = 1000
                });
            }

            Console.WriteLine("Ready...");
            Console.ReadKey();
        }
예제 #3
0
        //private void InitializeComponent()
        //{
        //    this.ServiceName = "LogChipper"; 
        //    this.CanHandleSessionChangeEvent = false;
        //    this.CanPauseAndContinue = false;
        //    this.CanShutdown = true;
        //    this.CanStop = Properties.Settings.Default.svcCanStop;
        //}

        protected override void OnStart(string[] args)
        {
            // prep for writing to local event log
            string eventLogName = Properties.Settings.Default.eventLogName;
            string eventLogSource = Properties.Settings.Default.eventLogSource;
            string machineName = ".";
            // warning: Event Log Source must have already been created during the installation
            eventLogger = new EventLog(eventLogName, machineName, eventLogSource);
            eventLogger.WriteEntry("LogChipper syslog forwarding service has started.", EventLogEntryType.Information, 0);

            // prep for posting to remote syslog
            bool useTCP = Properties.Settings.Default.syslogProtocol.ToUpper().Contains("TCP");
            syslogForwarder = new Syslog.Client(
                (string)Properties.Settings.Default.syslogServer,
                (int)Properties.Settings.Default.syslogPort,
                useTCP,
                (int)Syslog.Facility.Syslog,
                (int)Syslog.Level.Information);
            syslogForwarder.Send("[LogChipper syslog forwarding service has started.]");

            // prep to tail the local log file
            //fileName = Properties.Settings.Default.logFilePath;
            if (!File.Exists(fileName))
            {
                eventLogger.WriteEntry("Cannot locate target log file; exiting service.", EventLogEntryType.Error, 404);
                this.Stop();
                Environment.Exit(404); // not very graceful, but prevents more error messages from continuing OnStart after OnStop

                // TODO: handle missing target file more gracefully
                //    bool found = false;
                //
                //    // re-test every minute for 15 minutes
                //    for (int i = 0; i < 15; i++)
                //    {
                //        eventLogger.WriteEntry("Target log file not found; please check the configuration.", EventLogEntryType.Warning, 2);
                //        System.Threading.Thread.Sleep(60 * 1000);
                //        if (File.Exists(fileName))
                //        {
                //            found = true;
                //            break;
                //        }
                //    }
                //    if (!found)
                //    {
                //        eventLogger.WriteEntry("Target log file still doesn't exist; exiting service.", EventLogEntryType.Error, 404);
                //        Environment.Exit(1); // TODO: correct way to exit?
                //    }
            }

            // spin your thread
            if ((workerThread == null) || ((workerThread.ThreadState & 
                (System.Threading.ThreadState.Unstarted | System.Threading.ThreadState.Stopped)) != 0))
            {
                workerThread = new Thread(new ThreadStart(ServiceWorkerMethod));
                workerThread.Start();
            }
        }
예제 #4
0
        public static void Main(string[] args)
        {

            Syslog.Client c = new Syslog.Client("127.0.0.1", 514, false, (int)Syslog.Facility.Syslog, (int)Syslog.Level.Warning);
            try
            {
                c.Send("This is a test of the syslog client code.");
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                c.Close();
            }
        }