/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { // // Service1 // Properties.Settings settings = new Properties.Settings(); this.ServiceName = settings.ServiceName; }
/// <summary> /// Required designer variable. /// </summary> public SyslogdInstaller() { // Get user settings settings = new Properties.Settings(); // This call is required by the Designer. InitializeComponent(); // This call is required is you use network things going through XP firewalls FireWall(); }
/// <summary> /// Worker thread, setting up an listening socket for UDP datagrams /// </summary> private void Worker() { Properties.Settings settings = new Properties.Settings(); m_EventLog = settings.EventLog; IPAddress ipAddress = IPAddress.Any; if(settings.Address!="*") ipAddress = IPAddress.Parse(settings.Address); IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, settings.Port); m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); m_socket.Bind(ipEndPoint); // Recycling vars , i love it. EndPoint endPoint = ipEndPoint; // http://www.ietf.org/rfc/rfc3164.txt // 4.1 syslog Message Parts // The total length of the packet MUST be 1024 bytes or less. byte[] buffer = new byte[1024]; while (m_running) { try { int intReceived = m_socket.ReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref endPoint); string strReceived = Encoding.ASCII.GetString(buffer, 0, intReceived); Log(endPoint, strReceived); } catch (Exception exception) { EventLog myLog = new EventLog(); myLog.Source = settings.ServiceName; if (!m_running) myLog.WriteEntry("Stopping...", EventLogEntryType.Information); else myLog.WriteEntry(exception.Message, EventLogEntryType.Error); myLog.Close(); myLog.Dispose(); } } }