Exemple #1
0
        /// <summary>
        /// Return the first item found with MinPriority or higher.  The item is removed from the ErrorList.
        /// If no item matches the specified priority (or the list is empty), null is returned.
        /// </summary>
        /// <param name="minPriority"></param>
        /// <returns>entry or null</returns>
        public ErrorLogItem GetFirstItem(ErrorPriorities minPriority)
        {
            lock ( mResourceLock )
            {
                // Don't use 'ErrorList' -- we can't remove the item...
                foreach (ErrorLogItem item in mList)
                {
                    if ((int)item.Priority >= (int)minPriority)
                    {
                        // Remove the item from the ErrorList
                        mList.Remove(item);
                        return(item);
                    }
                }

                // If not in the local list, check the children
                foreach (IErrorLog child in mChildLogs)
                {
                    ErrorLogItem item = child.GetFirstItem(minPriority);
                    if (item != null)
                    {
                        return(item);
                    }
                }
            }
            return(null);
        }
Exemple #2
0
 public LogMessage(ErrorPriorities type, int code, string datestr, string message)
 {
     Type       = type;
     Code       = code;
     DateString = datestr;
     Message    = message;
 }
Exemple #3
0
        /// <summary>
        /// Throws the first item found with MinPriority or higher.  The item is removed from the ErrorList.
        /// InnerException will contain the original StackTrace.  If no item matches the specified priority
        /// (or the list is empty), no exception is thrown.
        /// </summary>
        /// <param name="minPriority"></param>
        public void ThrowFirstItem(ErrorPriorities minPriority)
        {
            ErrorLogItem item = GetFirstItem(minPriority);

            if (item != null)
            {
                // Don't directly throw the original item.Exception because throwing will
                // overwrite its StackTrace.  Instead, wrap it in a new exception
                // of the same type, with the original exception as InnerException.
                Exception ex = (Exception)Activator.CreateInstance(
                    item.Exception.GetType(),
                    new object[] { item.Message, item.Exception });
                // bye bye...
                throw ex;
            }
        }
Exemple #4
0
        /// <summary>
        /// Logs an Exception.
        /// </summary>
        /// <param name="ex">Exception to be logged</param>
        /// <param name="priority">WARNING or ERROR</param>
        protected void AddException(Exception ex, ErrorPriorities priority)
        {
            ErrorLogItem item;

            lock ( mResourceLock )
            {
                // this is a good place to print errors in debug builds
                Debug.Print(String.Format("{0} {1}: {2}", mSource, priority, ex.Message));

                item = new ErrorLogItem {
                    Priority = priority, Source = mSource, Exception = ex
                };
                mList.Add(item);
            }

            // if anyone is listening, raise an event.
            if (ErrorLogItemAdded != null)
            {
                ErrorLogItemAdded(this, new ErrorLogItemAddedArgs(item));
            }
        }
Exemple #5
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(Colors.Black);
            }
            ErrorPriorities messageType = (ErrorPriorities)value;

            switch (messageType)
            {
            case ErrorPriorities.Info:
                return(Brushes.Blue);

            case ErrorPriorities.Warning:
                return(Brushes.GreenYellow);

            case ErrorPriorities.Error:
                return(Brushes.Red);

            default:
                return(Brushes.Black);
            }
        }