public override void Init() { try { RegistryProcess rp = new RegistryProcess(); InitializeLogger logger = new InitializeLogger(rp.TRC_LEVEL); EventLog.WriteEntry("Security Manager Syslog Recorder", "Recorder init start", EventLogEntryType.Information); if (usingRegistry) // agent için geldi { if (!reg_flag) { if (!rp.get_regisryforAgent()) { return; } else if (!logger.Initialize(rp)) { return; } reg_flag = true; } } else // remote recorder için geldi { if (!reg_flag) { if (!rp.get_registryforRemoteRecorder(Id, location, trc_level)) { return; } else if (!logger.Initialize(rp)) { return; } reg_flag = true; } } if (usingRegistry) { InitializeLogger.L.Log(LogType.FILE, LogLevel.INFORM, "Start listening Syslogs on ip: " + Dns.GetHostEntry(Environment.MachineName.Trim()).AddressList[0].ToString() + " port: " + rp.SYSLOG_PORT.ToString()); try { slog = new Syslog(Dns.GetHostEntry(Environment.MachineName.Trim()).AddressList[0].ToString(), rp.SYSLOG_PORT, rp.PRO); } catch (Exception er) { InitializeLogger.L.Log(LogType.FILE, LogLevel.ERROR, "An error accuered while creating a syslog object for agent :" + er.Message); } } else { InitializeLogger.L.Log(LogType.FILE, LogLevel.INFORM, "Start listening Syslogs on ip: " + remote_host + " port: " + rp.SYSLOG_PORT.ToString()); try { slog = new Syslog(remote_host, rp.SYSLOG_PORT, rp.PRO); } catch (Exception er) { InitializeLogger.L.Log(LogType.FILE, LogLevel.ERROR, "An error accuered while creating a syslog object for remote recorder : " + er.Message); } } slog.Start(); slog.SyslogEvent += new Syslog.SyslogEventDelegate(slog_SyslogEvent); InitializeLogger.L.Log(LogType.FILE, LogLevel.INFORM, "Finish initializing Syslog Event"); EventLog.WriteEntry("Security Manager Syslog Recorder", "Recorder init start", EventLogEntryType.Information); } catch (Exception er) { EventLog.WriteEntry("Security Manager Syslog Recorder Init", er.ToString(), EventLogEntryType.Error); } }
public bool Initialize(RegistryProcess rp) { try { switch (trc_level) { case 0: { l.SetLogLevel(LogLevel.NONE); } break; case 1: { l.SetLogLevel(LogLevel.INFORM); } break; case 2: { l.SetLogLevel(LogLevel.WARN); } break; case 3: { l.SetLogLevel(LogLevel.ERROR); } break; case 4: { l.SetLogLevel(LogLevel.DEBUG); } break; } l.SetLogFile(rp.ERR_LOG); l.SetTimerInterval(LogType.FILE, logging_interval); l.SetLogFileSize(log_size); l.Log(LogType.FILE, LogLevel.INFORM, "Logger is initialized"); EventLog.WriteEntry("Security Manager Syslog Recorder", "Logger is initialized", EventLogEntryType.Information); return true; } catch (Exception er) { EventLog.WriteEntry("Security Manager Syslog Recorder", er.ToString(), EventLogEntryType.Error); return false; } }