public void LogErrorToDb(ErrorLogProp errorProp) { try { CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name)); ErrorLogDAL objErrorLogDAL = new ErrorLogDAL(); objErrorLogDAL.LogErrorToDb(errorProp); } catch (Exception e) { CommonDAL.logger.LogError(typeof(string), e); } finally { CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name)); } }
public static void LogErrorToDb(Exception ex) { try { ErrorLogProp errorProp = new ErrorLogProp(); System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true); //string message = ex.GetType().ToString()+ex.StackTrace.ToString(); errorProp.Message = string.Format("{0}: {1} \n{2}", ex.GetType().ToString(), ex.Message, ex.StackTrace.ToString()); errorProp.Logger = trace.GetFrame(0).GetMethod().ReflectedType.FullName; errorProp.Thread = trace.FrameCount.ToString(); errorProp.SystemMac = string.Format("PC Name: {0} Mac Address: {1}", Environment.MachineName, GetMACAddress()); errorProp.BuildVersion = ConfigurationManager.AppSettings["CurrentApplicationVersion"].ToString(); _serviceInstance.LogErrorToDb(errorProp); } catch (Exception e) { } }
public void LogErrorToDb(ErrorLogProp errorProp) { try { using (PortStorageEntities objAppWorksEntities = new PortStorageEntities()) { CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "Called {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name)); objAppWorksEntities.ErrorLogs.Add(new ErrorLog { SystemMac = errorProp.SystemMac, DateTime = DateTime.Now, Message = errorProp.Message, Level = "ERROR", Logger = errorProp.Logger, Thread = errorProp.Thread, BuildVersion = errorProp.BuildVersion }); objAppWorksEntities.SaveChanges(); } } catch (Exception e) { CommonDAL.logger.LogError(typeof(string), e); } finally { CommonDAL.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, "End {2} function ::{0} {1}.", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name)); } }