/// <summary> /// Logs an error in log for the application /// </summary> public void Log(Error error) { if (error == null) { throw new ArgumentNullException("error"); } // if we're in a retry state, log directly to the queue if (_isInRetry) { QueueError(error); ErrorEmailer.SendMail(error); return; } try { using (new TransactionScope(TransactionScopeOption.Suppress)) { LogError(error); } ErrorEmailer.SendMail(error); } catch (Exception ex) { _retryException = ex; // if we fail to write the error to the store, queue it for re-writing QueueError(error); } }
public static List <Sitelet> GetSiteletsByToken(string token) { SqlConnection conn = null; SqlCommand command = null; SqlDataReader reader = null; List <string> clients = new List <string>(); string result = string.Empty; List <Sitelet> Sitelets = new List <Sitelet>(); try { // create and open a connection object using (conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MLBStyleGuideConnectionString1"].ConnectionString)) { conn.Open(); using (command = new SqlCommand("[mlbstyleguide].[uspGetSiteletsByToken]", conn)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@token", SqlDbType.UniqueIdentifier).Value = new Guid(token); reader = command.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { var sitelet = new Sitelet(); sitelet.id = Convert.ToInt32(reader[0].ToString()); sitelet.description = reader[1].ToString(); Sitelets.Add(sitelet); } } } } catch (Exception ex) { ErrorEmailer.SendEmail(ex); } finally { if (reader != null) { reader.Close(); reader.Dispose(); } if (command != null) { command.Dispose(); } if (conn != null) { conn.Close(); } } //return clients; return(Sitelets); }
public static void SaveDownload(string token, int siteletID, string year, string file, string dateDownloaded) { SqlConnection conn = null; SqlCommand command = null; try { // create and open a connection object using (conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MLBStyleGuideConnectionString1"].ConnectionString)) { conn.Open(); using (command = new SqlCommand("[mlbstyleguide].[uspSaveDownload]", conn)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@Token", SqlDbType.UniqueIdentifier).Value = new Guid(token); command.Parameters.AddWithValue("@Section", GetSectionNameBySiteletID(siteletID)); command.Parameters.AddWithValue("@Year", year); command.Parameters.AddWithValue("@File", file); command.Parameters.AddWithValue("@DateDownloaded", Convert.ToDateTime(dateDownloaded)); command.ExecuteNonQuery(); } } } catch (Exception ex) { ErrorEmailer.SendEmail(ex); throw ex; } finally { if (command != null) { command.Dispose(); } if (conn != null) { conn.Close(); } } //return clients; }
static void Main() { // Example of code-only setup, alteratively this can be in the App.config // rollupSeconds is 0 so a new file is always generated, for demonstration purposes ErrorStore.Setup("Samples.Console", new JSONErrorStore(path: "Errors", rollupSeconds: 0)); // Example of a code-only email setup, alteratively this can be in the App.config var emailSettings = new EmailSettings { FromAddress = "*****@*****.**", FromDisplayName = "Bob the Builder", ToAddress = "*****@*****.**" }; ErrorEmailer.Setup(emailSettings); // Optional: for logging all unhandled exceptions AppDomain.CurrentDomain.UnhandledException += ExceptionalHandler; DisplayExceptionStats(); PauseForInput(); try { throw new Exception("Just a try/catch test"); } catch (Exception ex) { // logged, but caught so we don't crash ErrorStore.LogExceptionWithoutContext(ex); } DisplayExceptionStats(); PauseForInput(); System.Console.WriteLine("This next one will crash the program, but will be logged on the way out..."); PauseForInput(); // one not explicitly caught, will be logged by ExceptionHandler throw new Exception("I am an exception thrown on exit"); }
/// <summary> /// Logs an error in log for the application /// </summary> public void Log(Error error) { if (error == null) { throw new ArgumentNullException(nameof(error)); } // Track the GUID we made vs. what the store returns. If it's different, it's a dupe. var originalGuid = error.GUID; // if we're in a retry state, log directly to the queue if (_isInRetry) { QueueError(error); if (originalGuid != error.GUID) { error.IsDuplicate = true; } ErrorEmailer.SendMail(error); return; } try { using (new TransactionScope(TransactionScopeOption.Suppress)) { LogError(error); } if (originalGuid != error.GUID) { error.IsDuplicate = true; } ErrorEmailer.SendMail(error); } catch (Exception ex) { _retryException = ex; // if we fail to write the error to the store, queue it for re-writing QueueError(error); } }