コード例 #1
0
        public void Insert(LoggedEvent log)
        {
            var e = _events.FindById(log.Id);

            if (e == null)
            {
                try
                {
                    _events.Insert(new Event
                    {
                        Id        = log.Id,
                        Host      = log.Host,
                        Type      = log.Type,
                        StartTime = log.TimeStamp
                    });
                    return;
                } catch (Exception ex)
                {
                    if (!ex.Message.Contains("duplicate"))
                    {
                        throw ex;
                    }
                }
            }

            if (e == null)
            {
                e = _events.FindById(log.Id);
            }

            e.Duration = Math.Abs(e.StartTime - log.TimeStamp);
            e.Alert    = e.Duration > Event.AlertTreshold;

            _events.Update(e);
        }
コード例 #2
0
        public void Consume(BlockingCollection <LoggedEvent> queue)
        {
            while (!queue.IsCompleted)
            {
                LoggedEvent log = null;

                try
                {
                    log = queue.Take();
                }
                catch (InvalidOperationException) { }

                if (log != null)
                {
                    _db.Insert(log);
                }
            }
        }