public void WriteEntry(string message, EventLogEntryType type, string clientAlias = "") { BoostError error = new BoostError(); error.Time = DateTime.Now; error.Message = message; error.Type = type; error.Alias = clientAlias; //m_errSuffix should be populated with the service call and parameters if (m_errSuffix.Length > 0) //add suffix here to avoid threading issues error.Message += "\n" + m_errSuffix; else if (clientAlias.Length > 0) //if no suffix, then add client alias error.Message += "\nClientAlias = " + error.Alias; ThreadPool.QueueUserWorkItem(delegate(object e) { WriteEntry((BoostError)e); }, error); }
public string GetLastError(string alias) { string errMsg = ""; BoostError e = new BoostError(); if (GetLastError(alias, ref e)) { if (e.Message.Length < 1) errMsg = "No errors recorded for client alias: " + alias; else errMsg = "Type: " + e.Type.ToString() + "\nDate: " + e.Time.ToLongDateString() + "\nTime: " + e.Time.ToLongTimeString() + "\nMessage: " + e.Message; } else //client alias not found { errMsg = "Unable to retrieve last error. Client alias not found: " + alias; } return errMsg; //client alias not found }
public bool GetLastError(string alias, ref BoostError error) { if ((alias == null) || (alias.Length < 1)) alias = "4Tell"; foreach (ClientLog c in m_clients) if (c.Alias.Equals(alias)) { error = c.LastError; return true; } return false; }
//record the latest error that was encountered //return true if an existing client and false if it had to be added public bool AddLastError(BoostError error) { ClientLog client; bool found = GetClient(error.Alias, out client); client.LastError = error; return found; }
//private Error Log function to be run in a separate thread private void WriteEntry(BoostError error) { if (error.Message.Length < 1) return; //nothing to do bool blockLog = false; ClientPOC poc = new ClientPOC(); if ((error.Alias != null) && (error.Alias.Length > 0)) { foreach (ClientLog c in m_clients) if (c.Alias.Equals(error.Alias)) { poc = c.POC; break; } if (m_logBlockList != null) { //block this message from the log (if any clients are generating too many errors) foreach (string alias in m_logBlockList) if (alias.Equals(error.Alias)) { blockLog = true; break; } } } lock (m_errWriteLock) { //log all messages (unless blocked above) if (!blockLog && (m_eventLog != null)) m_eventLog.WriteEntry(error.Message, error.Type); //email certain messages //NOTE: no longer using m_clientReportLevel ---using ClientPOC from ConfigBoost string subject = ""; bool sendAdmin = true; bool sendClient = false; switch (error.Type) { case EventLogEntryType.Error: subject = "Error"; sendAdmin = ((int)m_adminReportLevel <= (int)(ReportLevel.Error)); sendClient = ((int)(poc.Report) <= (int)(ReportLevel.Error)); AddError(error.Alias); //add to error tally AddLastError(error); //replace last error break; case EventLogEntryType.Warning: subject = "Warning"; sendAdmin = ((int)m_adminReportLevel <= (int)(ReportLevel.Warrning)); sendClient = ((int)(poc.Report) <= (int)(ReportLevel.Warrning)); AddWarning(error.Alias); //add to warning tally AddLastError(error); //replace last error break; case EventLogEntryType.Information: subject = "Status Update"; sendAdmin = ((int)m_adminReportLevel <= (int)(ReportLevel.Information)); sendClient = ((int)(poc.Report) <= (int)(ReportLevel.Information)); break; default: subject = "Unknown EventType"; sendAdmin = true; sendClient = false; break; } if (sendClient && (poc.Email.Length > 0)) { string preMessage = "This is an auto-generated email from the 4-Tell Boost service." + "If you would rather not receive these email notices, please adjust " + "your configuration settings or contact us at [email protected]\n\n"; try { Gmail.GmailMessage.SendFromGmail(m_gmailUsername, m_gmailPassword, poc.Email, subject, preMessage + error.Message, m_ServerId, true); } catch (Exception ex) { string errMsg = "Error sending email to " + poc.Name + " <" + poc.Email + ">\n" + ex.Message + "\n\nOriginal message to send:\n" + preMessage + error.Message; if (!blockLog && (m_eventLog != null)) m_eventLog.WriteEntry(errMsg, EventLogEntryType.Error); } //always send admin messages that are sent to clients error.Message += "\n\nThis message was emailed to client: " + poc.Name + " <" + poc.Email + ">"; sendAdmin = true; } if (sendAdmin && (m_gmailToAddress.Length > 0)) { try { Gmail.GmailMessage.SendFromGmail(m_gmailUsername, m_gmailPassword, m_gmailToAddress, subject, error.Message, m_ServerId, true); } catch (Exception ex) { string errMsg = "Error sending email to " + m_gmailToAddress + "\n" + ex.Message + "\n\nOriginal message to send:\n" + error.Message; if (!blockLog && (m_eventLog != null)) m_eventLog.WriteEntry(errMsg, EventLogEntryType.Error); } } } //end errWritesLock }
public ClientLog(string alias) { Alias = alias; POC = new ClientPOC(); LastUpload = DateTime.MinValue; LastGenerator = DateTime.MinValue; LastError = new BoostError(); Calls = new Accumulator(alias, "Calls"); Errors = new Accumulator(alias, "Errors"); Warnings = new Accumulator(alias, "Warns"); ServiceCalls = new ServiceCallLog(alias); Actions = new ActionsLog(alias); Clicks = new ClickStreamLog(alias); }