예제 #1
0
        private void create_logs()
        {
            if (logs_created_)
            {
                return;
            }

            logs_created_ = true;
            lock (this) {
                foreach (var log in event_logs_)
                {
                    log.disposed_ = true;
                }
                event_logs_.Clear();
            }

            lock (this)
                foreach (var type in log_types)
                {
                    try {
                        var log = new log_info {
                            log_type = type, remote_machine_name = remote_machine_name, remote_domain = remote_domain_name, remote_user_name = remote_user_name
                        };
                        event_logs_.Add(log);
                        new Thread(() => read_single_log_thread(log))
                        {
                            IsBackground = true
                        }.Start();
                    } catch (Exception e) {
                        logger.Error("can't create event log " + type + "/" + remote_machine_name + " : " + e.Message);
                        errors_.add("Can't create Log " + type + " on machine " + remote_machine_name + ", Reason=" + e.Message);
                    }
                }
        }
예제 #2
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     login_data   = new user_info();
     general      = new general();
     product_info = new info_product();
     log_info     = new log_info();
     Application.Run(new autorization());
 }
예제 #3
0
        private void create_logs()
        {
            if (logs_created_)
            {
                return;
            }
            logs_created_ = true;
            logger.Debug("event_log - recreating logs ");

            foreach (var log in event_logs_)
            {
                log.disposed_ = true;
            }
            event_logs_ = new List <log_info>();
            lock (this) {
                has_done_gc_collect_ = false;

                if (lines_now_.Count > 0)
                {
                    logger.Warn("event log: did have elements on create_logs " + lines_now_.Count);
                    lines_now_.Clear();
                }
            }

            var new_event_logs = new List <log_info>();

            lock (this)
                foreach (var type in log_types)
                {
                    try {
                        var log = new log_info {
                            log_type = type, remote_machine_name = remote_machine_name, remote_domain = remote_domain_name, remote_user_name = remote_user_name
                        };
                        new_event_logs.Add(log);
                        new Thread(() => read_single_log_thread(log))
                        {
                            IsBackground = true
                        }.Start();
                    } catch (Exception e) {
                        logger.Error("can't create event log " + type + "/" + remote_machine_name + " : " + e.Message);
                        errors_.add("Can't create Log " + type + " on machine " + remote_machine_name + ", Reason=" + e.Message);
                    }
                }

            event_logs_ = new_event_logs;
        }
예제 #4
0
        private void read_single_log_thread(log_info log) {
            string query_string = "*";
            if (provider_name != "")
                query_string = "*[System/Provider/@Name=\"" + provider_name + "\"]";

            int max_event_count = int.MaxValue;
            // debugging - load much less, faster testing
            if (util.is_debug)
                max_event_count = 250;

            try {
                // we can read the number of entres only for local logs
                if (provider_name == "" && log.remote_machine_name == "") {
                    var dummy_log = new EventLog(log.log_type);
                    lock(this)
                        log.full_log_count_ = dummy_log.Entries.Count;
                    dummy_log.Dispose();
                }

                // waiting for user to set the password
                if ( log.remote_machine_name != "")
                    while ( remote_password_ == "")
                        Thread.Sleep(100);

                SecureString pwd = new SecureString();
                foreach ( char c in remote_password_)
                    pwd.AppendChar(c);
                EventLogSession session = log.remote_machine_name != "" ? new EventLogSession(log.remote_machine_name, remote_domain_name, remote_user_name, pwd, SessionAuthentication.Default) : null;
                pwd.Dispose();

                EventLogQuery query = new EventLogQuery(log.log_type, PathType.LogName, query_string);
                query.ReverseDirection = reverse_;
                if ( session != null)
                    query.Session = session;

                EventLogReader reader = new EventLogReader(query);
                int read_idx = 0;
                for (EventRecord rec = reader.ReadEvent(); rec != null && !log.disposed_ && read_idx++ < max_event_count ; rec = reader.ReadEvent())
                    lock (this) {
                        log.last_events_.Add(rec);
                        ++log.cur_log_count_;
                    }

                lock (this)
                    log.listening_for_new_events_ = true;

                // at this point, listen for new events
                if (reverse_) {
                    // if reverse, I need to create another query, or it won't allow watching
                    query = new EventLogQuery(log.log_type, PathType.LogName, query_string);                
                    if ( session != null)
                        query.Session = session;                    
                }
				using (var watcher = new EventLogWatcher(query))
				{
					watcher.EventRecordWritten += (o, e) => {
                        lock(this)
                            log.new_events_.Add(e.EventRecord);
					};
					watcher.Enabled = true;

                    while ( !log.disposed_)
                        Thread.Sleep(100);
				}

            } catch (Exception e) {
                logger.Error("can't create event log " + log.log_type + "/" + remote_machine_name + " : " + e.Message);
                errors_.add("Can't create Log " + log.log_type + " on machine " + remote_machine_name + ", Reason=" + e.Message);
            }
            
        }
예제 #5
0
        private void create_logs() {
            if (logs_created_)
                return;

            logs_created_ = true;
            lock (this) {
                foreach (var log in event_logs_)
                    log.disposed_ = true;
                event_logs_.Clear();
            }

            lock(this)
                foreach (var type in log_types) {
                    try {
                        var log = new log_info { log_type = type, remote_machine_name = remote_machine_name, remote_domain = remote_domain_name, remote_user_name = remote_user_name};
                        event_logs_.Add( log);
                        new Thread(() => read_single_log_thread(log)) {IsBackground = true }.Start();
                    } catch (Exception e) {
                        logger.Error("can't create event log " + type + "/" + remote_machine_name + " : " + e.Message);
                        errors_.add("Can't create Log " + type + " on machine " + remote_machine_name + ", Reason=" + e.Message);
                    }
                }
        }
예제 #6
0
        private void read_single_log_thread(log_info log)
        {
            string query_string = "*";

            if (provider_name != "")
            {
                query_string = "*[System/Provider/@Name=\"" + provider_name + "\"]";
            }

            int max_event_count = int.MaxValue;

            // debugging - load much less, faster testing
            if (util.is_debug)
            {
                max_event_count = 250;
            }

            try {
                // we can read the number of entres only for local logs
                if (provider_name == "" && log.remote_machine_name == "")
                {
                    var dummy_log = new EventLog(log.log_type);
                    lock (this)
                        log.full_log_count_ = dummy_log.Entries.Count;
                    dummy_log.Dispose();
                }

                // waiting for user to set the password
                if (log.remote_machine_name != "")
                {
                    while (remote_password_ == "")
                    {
                        Thread.Sleep(100);
                    }
                }

                SecureString pwd = new SecureString();
                foreach (char c in remote_password_)
                {
                    pwd.AppendChar(c);
                }
                EventLogSession session = log.remote_machine_name != "" ? new EventLogSession(log.remote_machine_name, remote_domain_name, remote_user_name, pwd, SessionAuthentication.Default) : null;
                pwd.Dispose();

                EventLogQuery query = new EventLogQuery(log.log_type, PathType.LogName, query_string);
                query.ReverseDirection = reverse_;
                if (session != null)
                {
                    query.Session = session;
                }

                EventLogReader reader   = new EventLogReader(query);
                int            read_idx = 0;
                for (EventRecord rec = reader.ReadEvent(); rec != null && !log.disposed_ && read_idx++ < max_event_count; rec = reader.ReadEvent())
                {
                    lock (this) {
                        log.last_events_.Add(rec);
                        ++log.cur_log_count_;
                    }
                }

                lock (this)
                    log.listening_for_new_events_ = true;

                // at this point, listen for new events
                if (reverse_)
                {
                    // if reverse, I need to create another query, or it won't allow watching
                    query = new EventLogQuery(log.log_type, PathType.LogName, query_string);
                    if (session != null)
                    {
                        query.Session = session;
                    }
                }
                using (var watcher = new EventLogWatcher(query))
                {
                    watcher.EventRecordWritten += (o, e) => {
                        lock (this)
                            log.new_events_.Add(e.EventRecord);
                    };
                    watcher.Enabled = true;

                    while (!log.disposed_)
                    {
                        Thread.Sleep(100);
                    }
                }
            } catch (Exception e) {
                logger.Error("can't create event log " + log.log_type + "/" + remote_machine_name + " : " + e.Message);
                errors_.add("Can't create Log " + log.log_type + " on machine " + remote_machine_name + ", Reason=" + e.Message);
            }
        }
예제 #7
0
        private void create_logs() {
            if (logs_created_)
                return;            
            logs_created_ = true;
            logger.Debug("event_log - recreating logs ");

            foreach (var log in event_logs_)
                log.disposed_ = true;
            event_logs_ = new List<log_info>();
            lock (this) {
                has_done_gc_collect_ = false;

                if (lines_now_.Count > 0) {
                    logger.Warn("event log: did have elements on create_logs " + lines_now_.Count);
                    lines_now_.Clear();
                }
            }

            var new_event_logs = new List<log_info>();
            lock(this)
                foreach (var type in log_types) {
                    try {
                        var log = new log_info { log_type = type, remote_machine_name = remote_machine_name, remote_domain = remote_domain_name, remote_user_name = remote_user_name};
                        new_event_logs.Add( log);
                        new Thread(() => read_single_log_thread(log)) {IsBackground = true }.Start();
                    } catch (Exception e) {
                        logger.Error("can't create event log " + type + "/" + remote_machine_name + " : " + e.Message);
                        errors_.add("Can't create Log " + type + " on machine " + remote_machine_name + ", Reason=" + e.Message);
                    }
                }

            event_logs_ = new_event_logs;
        }