public void SendExceptionMail(Data.Analytics.Exception reg) { using (var context = new Data.SizeUpContext()) { var strings = context.ResourceStrings.Where(i => i.Name.StartsWith("Exception.Email")).ToList(); var template = strings.Where(i => i.Name == "Exception.Email.Body").Select(i => i.Value).FirstOrDefault(); var subject = strings.Where(i => i.Name == "Exception.Email.Subject").Select(i => i.Value).FirstOrDefault(); var recipients = strings.Where(i => i.Name == "Exception.Email.Recipients").Select(i => i.Value).FirstOrDefault().Split(',').ToList(); var uri = HttpContext.Current.Request.Url; var t = Templates.TemplateFactory.GetTemplate(template); t.Add("Exception", reg.ExceptionText); //t.Add("PasswordResetKey", HttpContext.Current.Server.UrlEncode(user.GetEncryptedToken())); //t.Add("OptOutKey", HttpContext.Current.Server.UrlEncode(user.GetEncryptedToken())); //t.Add("AppDomain", uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port); //t.Add("AppDomain", (HttpContext.Current.Request.IsSecureConnection ? "https" : "http") + Uri.SchemeDelimiter + uri.Host); t.Add("AppDomain", (ConfigurationManager.AppSettings["HostingEnvironment"] == "LOCALHOST" ? "http" : "https") + Uri.SchemeDelimiter + uri.Host); string body = t.Render(); recipients.AsParallel().ForAll(r => SendMail(r, subject, body)); } }
public void Exception(Data.Analytics.Exception reg) { TimeStamp stamp = new TimeStamp(); reg.Day = stamp.Day; reg.Hour = stamp.Hour; reg.Minute = stamp.Minute; reg.Month = stamp.Month; reg.Quarter = stamp.Quarter; reg.Year = stamp.Year; reg.Week = stamp.Week; reg.Timestamp = stamp.Stamp; reg.Session = APIContext.Current.Session; Task.Factory.StartNew(() => { using (var context = ContextFactory.AnalyticsContext) { Mailer mail = new Mailer(); context.Exceptions.AddObject(reg); context.SaveChanges(); } }); }