public override void Log(ExceptionLoggerContext context) { var ex = context.Exception; var logText = HandleLogText(ex); var requestedURi = (string)context.Request.RequestUri.AbsoluteUri; var requestMethod = context.Request.Method.ToString(); var timeUtc = DateTime.Now; Error apiError = new Error { Message = logText, RequestUri = requestedURi, RequestMethod = requestMethod, TimeUtc = DateTime.Now }; try { DatabaseLogging.LogError(apiError); } catch (Exception) { throw; } }
public async Task <ActionResult> RunScheduled() { await RunNotificationEmails(); lock (obj) { DatabaseLogging logging = new DatabaseLogging(); DateTime now = DateTimeHelper.GetCurrentDateTimeByTimeZone(Constants.CurrentTimeZoneId); logging.Add($"Run Scheduled emails. Today is {now.DayOfWeek}. Time: {now.Hour}:{now.Minute}. Full: {now}"); if (now.DayOfWeek == DayOfWeek.Saturday || now.DayOfWeek == DayOfWeek.Sunday) { logging.Add("We don't send emails today " + now.DayOfWeek + " " + now); return(Content("We don't send emails today " + now.DayOfWeek + " " + now)); } if (now.Hour != 9) { logging.Add("time is not correct " + now.Hour + " Full: " + now); return(Content("time is not correct " + now.Hour + " Full: " + now)); } ScheduledEmailRepository emailRepository = new ScheduledEmailRepository(); IEmailService emailService = new GoogleEmailService(); #if DEBUG emailService = new SendGridEmailService(); #endif var scheduled = emailRepository.GetScheduled().ToList(); logging.Add($"Schedule time is fine. Got {scheduled.Count} emails to sent"); foreach (var email in scheduled) { try { emailService.SendIntroMail(email.CompanyId, email.Subject, email.Body, email.Email); emailRepository.UpdateStatus(email.Id, EmailStatus.Sent); logging.Add($"Email {email.Id} is sent"); } catch (Exception e) { emailRepository.UpdateStatus(email.Id, EmailStatus.Failed); logging.Add($"Email {email.Id} is failed. Error: {e.Message}"); } } logging.Add($"***Scheduled emails are done***"); } return(Content("OK")); }
public NotificationService(IRepository <Notification> notificationRepository, IRepository <Company> companyRepository, IRepository <Follower> followerRepository, IRepository <Connection> connectionRepository, IRepository <News> newsRepositoty, IRepository <Comment> commentRepositoty, IRepository <ProcessedNotifications> processedNotificationRepository, IRepository <NotificationSettings> notificationSettingsRepository) { _notificationRepository = notificationRepository; _companyRepository = companyRepository; _followerRepository = followerRepository; _connectionRepository = connectionRepository; _newsRepositoty = newsRepositoty; _commentRepositoty = commentRepositoty; _processedNotificationRepository = processedNotificationRepository; _notificationSettingsRepository = notificationSettingsRepository; logging = new DatabaseLogging(); }
private void OutgoingMessageAsync(Audit audit) { audit.RequestType = "Response"; DatabaseLogging.Audit(audit); }
private void IncomingMessageAsync(Audit audit) { audit.RequestType = "Request"; DatabaseLogging.Audit(audit); }