/// <summary> /// Saves the exception details to ErrorLogging db with specified ImpactLevel and user message /// </summary> /// <param name="ex">The exception</param> /// <param name="impactLevel">The impact level.</param> /// <param name="errorDescription">The error Description.</param> public static void Save(this Exception ex, ImpactLevel impactLevel, string errorDescription) { using (var db = new ErrorLoggingDataContext()) { Log log = new Log(); if (errorDescription != null && errorDescription != "") { log.ErrorShortDescription = errorDescription; } log.ExceptionType = ex.GetType().FullName; var stackTrace = new StackTrace(ex, true); var allFrames = stackTrace.GetFrames().ToList(); foreach (var frame in allFrames) { log.FileName = frame.GetFileName(); log.LineNumber = frame.GetFileLineNumber(); var method = frame.GetMethod(); log.MethodName = method.Name; log.ClassName = frame.GetMethod().DeclaringType.ToString(); } log.ImpactLevel = impactLevel.ToString(); try { log.ApplicationName = Assembly.GetCallingAssembly().GetName().Name; } catch { log.ApplicationName = ""; } log.ErrorMessage = ex.Message; log.StackTrace = ex.StackTrace; if (ex.InnerException != null) { log.InnerException = ex.InnerException.ToString(); log.InnerExceptionMessage = ex.InnerException.Message; } log.IpAddress = ""; //get the ip address if (System.Diagnostics.Debugger.IsAttached) { log.IsProduction = false; } try { db.Logs.InsertOnSubmit(log); db.SubmitChanges(); } catch (Exception eex) { } } }
public virtual void WriteToErrorLog(ArrayList list) { ErrorLoggingDataContext logger = new ErrorLoggingDataContext(); ErrorStack tblError = new ErrorStack(); tblError.CreatedDate = DateTime.Now; if (!string.IsNullOrEmpty(list[2].ToString())) { tblError.RequestorIp = list[2].ToString(); } if (!string.IsNullOrEmpty(list[3].ToString())) { tblError.StackTrace = list[3].ToString(); } if (!string.IsNullOrEmpty(list[1].ToString())) { tblError.newId = Guid.Parse(list[1].ToString()); } logger.ErrorStacks.InsertOnSubmit(tblError); logger.SubmitChanges(); }
/// <summary> /// Saves the exception details to ErrorLogging db with specified ImpactLevel and user message /// </summary> /// <param name="ex">The exception</param> /// <param name="impactLevel">The impact level.</param> /// <param name="errorDescription">The error Description.</param> public static void Save(this Exception ex, ImpactLevel impactLevel, string errorDescription) { using (var db = new ErrorLoggingDataContext()) { Log log = new Log(); if (errorDescription != null && errorDescription != "") { log.ErrorShortDescription = errorDescription; } log.ExceptionType = ex.GetType().FullName; var stackTrace = new StackTrace(ex, true); var allFrames = stackTrace.GetFrames().ToList(); foreach (var frame in allFrames) { log.FileName = frame.GetFileName(); log.LineNumber = frame.GetFileLineNumber(); var method = frame.GetMethod(); log.MethodName = method.Name; log.ClassName = frame.GetMethod().DeclaringType.ToString(); } log.ImpactLevel = impactLevel.ToString(); try { log.ApplicationName = Assembly.GetCallingAssembly().GetName().Name; } catch { log.ApplicationName = ""; } log.ErrorMessage = ex.Message; log.StackTrace = ex.StackTrace; if (ex.InnerException != null) { log.InnerException = ex.InnerException.ToString(); log.InnerExceptionMessage = ex.InnerException.Message; } //var methodsName = System.Reflection.MethodBase.GetCurrentMethod(); //string projectName=System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString(); string whosOnCookie = Email.FindCookieValue("whoson"); if (!string.IsNullOrEmpty(whosOnCookie)) { log.WhosOnCookie = whosOnCookie; } string commercerserverId = Email.FindCookieValue("COMMERCE_SITE_Identity"); if (!string.IsNullOrEmpty(commercerserverId)) { log.CommerceServerId = commercerserverId; } log.IpAddress = Email.GetIPAddress(); if (System.Diagnostics.Debugger.IsAttached) { log.IsProduction = false; } try { db.Logs.InsertOnSubmit(log); db.SubmitChanges(); } catch (Exception eex) { } } }