Example #1
0
        /// <summary>
        /// Log an error and return the error number
        /// </summary>
        /// <param name="redirect">Redirect after logging?</param>
        /// <returns>Error number</returns>
        public static Int64 Log(System.Exception ex, Types type, bool redirect, string note)
        {
            Idaho.Exception exception = new Idaho.Exception(ex, redirect, note, type);
            Int64           id        = exception.Save();

            if (type.Contains(Types.SendEmail))
            {
                Assert.NoNull(_emailTo, "NullMailTo");
                string key = ex.Message;
                if (!_occurrences.ContainsKey(key))
                {
                    _occurrences.Add(key, new Stack <DateTime>());
                }
                Stack <DateTime> oc = _occurrences[key];

                if (oc.Count == 0 || TimeSpan.Compare(
                        DateTime.Now.Subtract(oc.Peek()), _queueTime) >= 0)
                {
                    // at least frequency number of minutes have passed since last mail

                    Idaho.Web.Email    mail      = new Idaho.Web.Email();
                    List <MailAddress> addresses = new List <MailAddress>();

                    addresses.Add(_emailTo);

                    if (type.Contains(Types.HostEmail) && _hostMailTo != null &&
                        !addresses.Contains(_hostMailTo))
                    {
                        addresses.Add(_hostMailTo);
                    }

                    mail.Error(exception, addresses, oc.Count);

                    // reset the stack
                    if (oc.Count > 0)
                    {
                        oc.Clear();
                    }
                }
                oc.Push(DateTime.Now);
            }
            return(id);
        }