public static void Save(this Exception ex, ImpactLevel impactLevel, string errorDescription) { using (var db = new DataContext()) { Log log = new Log(); if (errorDescription != null && errorDescription != "") { log.ErrorMessage = 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.AppName = Assembly.GetCallingAssembly().GetName().Name; } catch { log.AppName = ""; } log.ErrorMessage = ex.Message; log.StackTrace = ex.StackTrace; if (ex.InnerException != null) { log.InnerException = ex.InnerException.ToString(); log.InnerExceptionMessage = ex.InnerException.Message; } try { log.CreatedAt = DateTime.Now; db.Logs.Add(log); db.SaveChanges(); } catch (Exception e) { } } }
/// <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) { } } }
/// <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) { } } }
public static Data.Log Save(this Exception ex, HttpSessionStateBase Session, string callDetail, ImpactLevel impactLevel, string errorDescription) { using (var db = new ScreenPlayCRMEntities()) { Data.Log log = new Data.Log(); log.ContactId = SessionControl.SessionManager.GetContactId(Session); log.ClientId = SessionControl.SessionManager.GetClientId(Session); log.UserId = SessionControl.SessionManager.GetUserId(Session); log.CallDetail = callDetail; log.ErrorDate = DateTime.Now; log.LastModified = DateTime.Now; 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 = ""; try { db.Logs.Add(log); db.SaveChanges(); } catch (Exception eex) { } return(log); } }
/// <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 SMS.Models.SMSDbContext()) { 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 = HttpContext.Current.Request.UserHostAddress; //get the ip address //log.HostName = HttpContext.Current.Request; //get the host name try { IPHostEntry host = Dns.GetHostEntry(log.IpAddress); log.HostName = host.HostName; } catch (SocketException se) { log.HostName = "Mobile/Unknown Host"; } log.ErrorDate = DateTime.Now; if (System.Diagnostics.Debugger.IsAttached) { log.IsProduction = false; } try { db.Logs.Add(log); db.SaveChanges(); } catch (Exception eex) { } finally { log.Dispose(); } } }