Пример #1
0
        private void ProcessLog()
        {
            ItemCollection items = this.logListView.Items;
            LogEntry       entry;
            LogAdapter     item = null;

            do
            {
                // get a log entry from the log queue
                lock (this.logQueueLocker) {
                    if (this.logQueue.Count <= 0)
                    {
                        if (item != null && this.chaseLastLogMenuItem.IsChecked)
                        {
                            // ensure the added item is visible
                            this.logListView.ScrollIntoView(item);
                        }
                        this.processing = false;
                        break;
                    }
                    entry = logQueue.Dequeue();
                }

                // remove some items if the count reaches the limit
                if (this.maxLogCount <= items.Count)
                {
                    // make 10 rooms at a once
                    for (int i = 9; 0 <= i; --i)
                    {
                        items.RemoveAt(i);
                    }
                }

                // add to the list view
                item = new LogAdapter(entry);
                items.Add(item);
            } while (true);

            return;
        }
        private Brush GetForeground(LogAdapter entry)
        {
            if (entry != null)
            {
                switch (entry.EventType)
                {
                case TraceEventType.Critical:
                    return(Brushes.Red);

                case TraceEventType.Error:
                    return(Brushes.Magenta);

                case TraceEventType.Warning:
                    return(Brushes.Olive);

                case TraceEventType.Information:
                    return(Brushes.Green);
                }
            }

            return(Brushes.Gray);
        }