示例#1
0
        private void MakeFullDbLog(List <Tuple <EventLog, T> > itemsToLog)
        {
            //to make full db log the Entity needs to be ILoggable
            try
            {
                using (dbContextLog = new UMS_LOGEntities())
                {
                    for (int i = 0; i < itemsToLog.Count; i++)
                    {
                        EventFullLog eventFullLog = new EventFullLog();
                        SetEventLogInfoFull(eventFullLog, itemsToLog[i].Item1);


                        XmlDocument doc = XMLLogHelper.CreateNewXMLDoc(eventFullLog.EntityActionName);
                        SetAllProperties(doc, itemsToLog[i].Item2);
                        eventFullLog.FullLogPropertiesXML = XMLLogHelper.SringValueOf(doc);


                        //make async log in a different database by the simple log and the entity that is being saved
                        if (typeof(ICustomLoggable).IsAssignableFrom(typeof(T)))
                        {
                            ((ICustomLoggable)itemsToLog[i].Item2).CreateMeaningfulEntityLogXML(eventFullLog);
                        }


                        dbContextLog.AddToEventFullLogs(eventFullLog);
                        dbContextLog.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                BaseHelper.Log("Грешка при детайлно създаване на EventLog на entity " + savedEntity.GetType().FullName);
                BaseHelper.Log(e.Message);
            }
        }
示例#2
0
        public static void SetAllProperties(XmlDocument doc, T savedEntity)
        {
            Type savedEntityType = savedEntity.GetType();

            var savedEntityProperties = savedEntityType.GetProperties();

            for (int i = 0; i < savedEntityProperties.Length; i++)
            {
                var propSourse = savedEntityProperties[i];
                if (propSourse.CanRead && propSourse.CanWrite)
                {
                    var valueEntity = savedEntityType.GetProperty(propSourse.Name);
                    var value       = "";
                    try
                    {
                        value = valueEntity.GetValue(savedEntity, null) != null?valueEntity.GetValue(savedEntity, null).ToString() : null;
                    }
                    catch (Exception ex)
                    {
                        //sometimes throws exception becouse it's the prop has complex getter like:
                        //public string CourseText { get; set; }
                        // public int CourseTextInt { get { return int.Parse(this.CourseText); } set {this.CourseTextInt=value ;} }
                        continue;
                    }

                    string propertyName = valueEntity.Name.Trim(' ');
                    if (value != null && value.ToString() != "" && !string.IsNullOrEmpty(propertyName)

                        && !value.ToString().Contains("EntityCollection") &&
                        !value.ToString().Contains("EntityReference"))
                    {
                        XMLLogHelper.AppendValueToMainNode(doc, propertyName, value.ToString());
                    }
                }
            }
        }