public static ErrorObject GetErrorObject(Exception e, Type type, HttpContext context, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { if (context != null) return GenerateErrorObject(e, type, errorGroup, errorSeverity, GetSessionData(ref context), GetCookieData(ref context), GetUserData(ref context), GetServerVariablesData(ref context), parameters, additionalInformation); else return GenerateErrorObject(e, type, errorGroup, errorSeverity, null, null, null, null, parameters, additionalInformation); }
public static void Save(Exception e, MobileTypeEnum mobileType, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { Task<bool>.Factory.StartNew( () => { try { string dt = DateTime.UtcNow.ToString("yyyyMMddHHmmss"); //string version = MobileTypeEnum.Android.ToString() + ":" + MobileConfig.MOBILE_VERSION_NUMBER_ANDROID; var stream = ErrorManagerMobile.SaveErrorObject(e, e.GetType(), additionalInformation: additionalInformation + LoggerMobile.Instance.getLoggedMessages()); var status = Reachability.IsHostReachable(Reachability.HostName); if (status) { try { var response = RDN.Utilities.Network.Network.SendPackage(stream, ServerConfig.ERROR_SUBMIT_URL); } catch (Exception ex) { } } } catch (Exception exception) { } return true; }); }
public static void Save(Exception e, MobileTypeEnum mobileType, Context context, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { Task<bool>.Factory.StartNew( () => { try { string dt = DateTime.UtcNow.ToString("yyyyMMddHHmmss"); //string version = MobileTypeEnum.Android.ToString() + ":" + MobileConfig.MOBILE_VERSION_NUMBER_ANDROID; var stream = ErrorManagerMobile.SaveErrorObject(e, e.GetType(), additionalInformation: additionalInformation + LoggerMobile.Instance.getLoggedMessages()); var connectivityManager = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService); var activeConnection = connectivityManager.ActiveNetworkInfo; if ((activeConnection != null) && activeConnection.IsConnected) { try { var response = Network.SendPackage(stream, ServerConfig.ERROR_SUBMIT_URL); } catch (Exception ex) { } } } catch (Exception exception) { } return true; }); }
/// <summary> /// Summarizes an exception into an object that can be sent to the error management system of rdnation /// </summary> /// <param name="e">The exception</param> /// <param name="type">The type information from the class where this occured. Can be obtained by using this.GetType() or just GetType()</param> /// <param name="stream">The object will be added to this stream.</param> /// <param name="errorGroup">The group where to put the error. Used for sorting on the error display webpage.</param> /// <param name="errorSeverity">The severity of the error. Used for sorting on the error display webpage.</param> /// <param name="parameters">Parameters or variables that whose vaules should be saved. Easiest is to get a list from this class, var v = ErrorManager.GetEmptyErrorList(); and then add the data like this: v.Add( () => myImportantVariable ); Variables, arrays, lists and dictionaries work.</param> /// <param name="additionalInformation">Additional information that could be useful.</param> public static void GetErrorObjectStream(Exception e, Type type, out Stream stream, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { HttpContext context = HttpContext.Current; if (context != null) GetErrorObjectStream(GenerateErrorObject(e, type, errorGroup, errorSeverity, GetSessionData(ref context), GetCookieData(ref context), GetUserData(ref context), GetServerVariablesData(ref context), parameters, additionalInformation), out stream); else GetErrorObjectStream(GenerateErrorObject(e, type, errorGroup, errorSeverity, null, null, null, null, parameters, additionalInformation), out stream); }
public static void Save(Exception e, Type type, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { Task<bool>.Factory.StartNew( () => { try { string dt = DateTime.UtcNow.ToString("yyyyMMddHHmmss"); //we save the error to the computer so that its backed up before we send it off to the server. ErrorManager.SaveErrorObject(e, type, ScoreboardConfig.SAVE_ERRORS_FOLDER + "Error" + dt + ".data", errorGroup, errorSeverity, parameters, ScoreboardConfig.SCOREBOARD_VERSION_NUMBER + ": " + additionalInformation); Stream stream; ErrorManager.LoadErrorObject(out stream, ScoreboardConfig.SAVE_ERRORS_FOLDER + "Error" + dt + ".data"); if (Network.Internet.CheckConnection()) { try { System.Net.HttpStatusCode response; response = RDN.Utilities.Network.Network.SendPackage(stream, ServerConfig.ERROR_SUBMIT_URL); if (response == HttpStatusCode.OK) { FileInfo file = new FileInfo(ScoreboardConfig.SAVE_ERRORS_FOLDER + "Error" + dt + ".data"); file.Delete(); } } catch (Exception ex) { var d = ex; } } } catch { } return true; }); }
/// <summary> /// Summarizes an exception into an object that can be sent to the error management system of rdnation /// </summary> /// <param name="e">The exception</param> /// <param name="type">The type information from the class where this occured. Can be obtained by using this.GetType() or just GetType()</param> /// <param name="path">Path to the final destination. Remember to add a fully qualified filename. Example: c:\myfolder\myfile.data</param> /// <param name="errorGroup">The group where to put the error. Used for sorting on the error display webpage.</param> /// <param name="errorSeverity">The severity of the error. Used for sorting on the error display webpage.</param> /// <param name="parameters">Parameters or variables that whose vaules should be saved. Easiest is to get a list from this class, var v = ErrorManager.GetEmptyErrorList(); and then add the data like this: v.Add( () => myImportantVariable ); Variables, arrays, lists and dictionaries work.</param> /// <param name="additionalInformation">Additional information that could be useful.</param> public static Stream SaveErrorObject(Exception e, Type type, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { return SaveErrorObject(GenerateErrorObject(e, type, errorGroup, errorSeverity, null, null, null, null, parameters, additionalInformation)); }
/// <summary> /// Summarizes an exception into an object that can be sent to the error management system of rdnation /// </summary> /// <param name="e">The exception</param> /// <param name="type">The type information from the class where this occured. Can be obtained by using this.GetType() or just GetType()</param> /// <param name="stream">The object will be added to this stream.</param> /// <param name="errorGroup">The group where to put the error. Used for sorting on the error display webpage.</param> /// <param name="errorSeverity">The severity of the error. Used for sorting on the error display webpage.</param> /// <param name="parameters">Parameters or variables that whose vaules should be saved. Easiest is to get a list from this class, var v = ErrorManager.GetEmptyErrorList(); and then add the data like this: v.Add( () => myImportantVariable ); Variables, arrays, lists and dictionaries work.</param> /// <param name="additionalInformation">Additional information that could be useful.</param> public static void GetErrorObjectStream(Exception e, Type type, out Stream stream, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { GetErrorObjectStream(GenerateErrorObject(e, type, errorGroup, errorSeverity, null, null, null, null, parameters, additionalInformation), out stream); }
protected static ErrorObject GenerateErrorObject(Exception e, Type type = null, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IDictionary<string, string> sessionData = null, IDictionary<string, string> cookieData = null, IDictionary<string, string> userData = null, IDictionary<string, string> serverVariablesData = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { var output = new ErrorObject(e) { ErrorGroup = errorGroup, ErrorSeverity = errorSeverity, AdditionalInformation = additionalInformation }; #region Parameter data // Do we have any parameter or variable ? if (parameters != null && parameters.Count > 0) { var parameterValue = new StringBuilder(); foreach (var parameter in parameters) { parameterValue.Clear(); // Clear old values var detail = new ErrorDataDetail { Key = string.Empty, Value = string.Empty, DataType = ErrorDataDetail.ErrorDataType.Parameter }; // Get the name and value seperatly in case one of them fails. try { // Get the parameter name var expression = parameter.Body as UnaryExpression; if (expression != null) { var expression2 = (MemberExpression)expression.Operand; detail.Key = expression2.Member.Name; } else { var expression2 = (MemberExpression)parameter.Body; detail.Key = expression2.Member.Name; } } catch (Exception) { detail.Key = "Unknown (error)"; } try { // Get the parameter value by compiling it and retrieving the value var invokedData = parameter.Compile().Invoke(); // Check if its a dictionary var collection = invokedData as IDictionary; if (collection != null) { // The keys in the collection var keys = collection.Keys; // Loop through the keys and write key/value foreach (var key in keys) parameterValue.Append(string.Format("{0}={1}, ", key, collection[key])); // If we have added something to the value, then remove the ,{space} at the end of the string detail.Value = parameterValue.Length > 0 ? parameterValue.ToString().Substring(0, parameterValue.Length - 2) : parameterValue.ToString(); output.ErrorData.Add(detail); continue; } // Check if its a list var list = invokedData as IList; if (list != null) { // Loop through the data and write it foreach (var colData in list) parameterValue.Append(string.Format("{0}, ", colData)); // If we have added something to the value, then remove the ,{space} at the end of the string detail.Value = parameterValue.Length > 0 ? parameterValue.ToString().Substring(0, parameterValue.Length - 2) : parameterValue.ToString(); output.ErrorData.Add(detail); continue; } if (invokedData == null || String.IsNullOrEmpty(invokedData.ToString())) { // Save the value detail.Value = string.Empty; output.ErrorData.Add(detail); } else { // Save the value detail.Value = invokedData.ToString(); output.ErrorData.Add(detail); } } catch (Exception) { detail.Value = "Unknown (error)"; output.ErrorData.Add(detail); } } } #endregion if (sessionData != null && sessionData.Count > 0) { foreach (var session in sessionData) { output.ErrorData.Add(new ErrorDataDetail { Key = session.Key, Value = session.Value, DataType = ErrorDataDetail.ErrorDataType.Session }); } } if (userData != null && userData.Count > 0) { foreach (var user in userData) { output.ErrorData.Add(new ErrorDataDetail { Key = user.Key, Value = user.Value, DataType = ErrorDataDetail.ErrorDataType.UserData }); } } if (cookieData != null && cookieData.Count > 0) { foreach (var cookie in cookieData) { output.ErrorData.Add(new ErrorDataDetail { Key = cookie.Key, Value = cookie.Value, DataType = ErrorDataDetail.ErrorDataType.Cookie }); } } if (serverVariablesData != null && serverVariablesData.Count > 0) { foreach (var serverVariable in serverVariablesData) { output.ErrorData.Add(new ErrorDataDetail { Key = serverVariable.Key, Value = serverVariable.Value, DataType = ErrorDataDetail.ErrorDataType.ServerVariable }); } } var assembly = type.Assembly; //var assemblyInfo = assembly.GetName(); //output.AssemblyName = assemblyInfo.Name; //output.AssemblyVersion = assemblyInfo.Version.ToString(); output.Created = DateTime.UtcNow; output.NameSpace = type.Namespace; //output.ErrorNameSpace = e.Source; output.MethodName = type.Name.IndexOf('`') > 0 ? type.Name.Substring(0, type.Name.IndexOf('`')) : type.Name; return output; }
private static void ViewObjectDebug(Exception e, Type type, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, Dictionary<string, string> sessionData = null, Dictionary<string, string> userData = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { //CultureInfo info = new CultureInfo("en"); //Thread.CurrentThread.CurrentCulture = info; //Thread.CurrentThread.CurrentUICulture = info; //// Gets the assembly information //var assembly = type.Assembly; //var assemblyInfo = assembly.GetName(); //WriteData.WriteLine(" - Error handling - "); //WriteData.WriteLine("Occured", DateTime.UtcNow.ToLongDateString() + " " + DateTime.Now.ToLongTimeString()); //WriteData.WriteLine("Assembly name", assemblyInfo.Name); //WriteData.WriteLine("Version", assemblyInfo.Version.ToString()); //WriteData.WriteLine("Group",ErrorGroupEnum.HasValue ? errorGroup.Value.ToString() : string.Empty); //WriteData.WriteLine("Severity", errorSeverity.HasValue ? errorSeverity.Value.ToString() : string.Empty); //WriteData.WriteEmptyLine(); //// WriteLine namespace and method name //WriteData.WriteLine("Namespace", type.Namespace); //WriteData.WriteLine("Error namespace", e.Source); //if (type.Name.IndexOf('`') > 0) // WriteData.WriteLine("Method", type.Name.Substring(0, type.Name.IndexOf('`'))); //else // WriteData.WriteLine("Method", type.Name); //WriteData.WriteEmptyLine(); //// Parameters and variables //WriteData.WriteLine(" - Parameters/Variables - "); //if (parameters != null && parameters.Any()) //{ // foreach (var parameter in parameters) // { // // Get the parameter name // string parameterName; // var expression = parameter.Body as UnaryExpression; // if (expression != null) // { // var expression2 = (MemberExpression)expression.Operand; // parameterName = expression2.Member.Name; // } // else // { // var expression2 = (MemberExpression)parameter.Body; // parameterName = expression2.Member.Name; // } // // Get the parameter value by compiling it and retrieving the value // var parameterValue = parameter.Compile().Invoke().ToString(); // WriteData.WriteLine(parameterName, parameterValue); // } //} //WriteData.WriteEmptyLine(); //// Trace //int traceLevel = 1; //WriteInnerExceptions(e, ref traceLevel); //WriteData.WriteEmptyLine(); //// Session and user data //WriteData.WriteLine("- Sessions -"); //foreach (var sessionInfo in sessionData) // WriteData.WriteLine(sessionInfo.Key, sessionInfo.Value); //WriteData.WriteEmptyLine(); //WriteData.WriteLine("- User -"); //foreach (var userInfo in userData) // WriteData.WriteLine(userInfo.Key, userInfo.Value); //// Additional information //WriteData.WriteLine("Additional information", additionalInformation); }
public static void AddExceptionEmailServer(Exception e, Type type, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { AddExceptionEmails(ErrorManager.GetErrorObject(e, type, errorGroup, errorSeverity, parameters, additionalInformation)); }
/// <summary> /// Summarizes an exception into an object that then is stored in the database /// </summary> /// <param name="e">The exception</param> /// <param name="type">The type information from the class where this occured. Can be obtained by using this.GetType() or just GetType()</param> /// <param name="errorGroup">The group where to put the error. Used for sorting on the error display webpage.</param> /// <param name="errorSeverity">The severity of the error. Used for sorting on the error display webpage.</param> /// <param name="parameters">Parameters or variables that whose vaules should be saved. Easiest is to get a list from this class, var v = ErrorManager.GetEmptyErrorList(); and then add the data like this: v.Add( () => myImportantVariable ); Variables, arrays, lists and dictionaries work.</param> /// <param name="additionalInformation">Additional information that could be useful.</param> public static void AddException(Exception e, Type type, ErrorGroupEnum? errorGroup = null, ErrorSeverityEnum? errorSeverity = null, IList<Expression<Func<object>>> parameters = null, string additionalInformation = null) { AddException(ErrorManagerWeb.GetErrorObject(e, type, HttpContext.Current, errorGroup, errorSeverity, parameters, additionalInformation)); }