private static EventLog getEntity(LoggingEventWrap evtw)
 {
     EventLog log = new EventLog();
     log.ID = Guid.NewGuid().ToString();
     log.AppAgent = evtw.Evt.UserName;
     log.AppDomain = evtw.Evt.Domain;
     log.AppID = App != null ? App.ID : null;
     log.EventLevel = evtw.Evt.Level.Name;
     if (evtw.Evt.ExceptionObject != null)
     {
         log.ExceptionInfo = excpetionToString(evtw.Evt.ExceptionObject);
         //it's important to turn this on for delay loaded properties
         log.IsExceptionInfoLoaded = true;
     }
     log.LoggerName = evtw.Evt.LoggerName;
     TracedLogMessage tmsg = null;
     if (evtw.Evt.MessageObject is TracedLogMessage)
     {
         tmsg = evtw.Evt.MessageObject as TracedLogMessage;
         log.Message_ = tmsg.Msg;
         log.CallTrackID = tmsg.ID;
     }
     else if (evtw.Evt.MessageObject is string)
         log.Message_ = evtw.Evt.MessageObject as string;
     else
         log.Message_ = evtw.Evt.RenderedMessage;
     log.ThreadName_ = evtw.Evt.ThreadName;
     log.ThreadPrincipal = evtw.Evt.Identity;
     log.TimeStamp_ = evtw.Evt.TimeStamp.Ticks;
     log.Username = evtw.webUser == null ? evtw.Evt.UserName : evtw.webUser;
     log.PageUrl = evtw.pageUrl;
     log.ReferringUrl = evtw.referUrl;
     if (tmsg == null)
         log.CallTrackID = evtw.requestId;
     if (evtw.Evt.Level >= Level.Debug &&  evtw.Evt.LocationInformation != null && _recordStackFrames)
         log.ChangedEventLocations = new EventLocation[] { getLocation(log.ID, evtw.Evt.LocationInformation) };
     return log;
 }
 /// <summary>
 /// <see cref="EventLocation.EventLogRef" /> is not initialized when the entity is created. Clients could call this method to load it provided a proper delegate <see cref="EventLocation.DelLoadEventLogRef" /> was setup
 /// before calling it.
 /// </summary>
 public void LoadEventLogRef()
 {
     if (_EventLogRef != null)
         return;
     if (DelLoadEventLogRef != null)
         _EventLogRef = DelLoadEventLogRef();
 }
 /// <summary>
 /// Internal use
 /// </summary>
 public EventLog ShallowCopy(bool allData = false, bool preserveState = false, bool checkLoadState = false)
 {
     EventLog e = new EventLog();
     e.StartAutoUpdating = false;
     e.ID = ID;
     e.EventLevel = EventLevel;
     e.LoggerName = LoggerName;
     e.Message_ = Message_;
     e.TimeStamp_ = TimeStamp_;
     e.AppAgent = AppAgent;
     e.AppDomain = AppDomain;
     e.CallTrackID = CallTrackID;
     e.PageUrl = PageUrl;
     e.ReferringUrl = ReferringUrl;
     e.ThreadName_ = ThreadName_;
     e.ThreadPrincipal = ThreadPrincipal;
     e.Username = Username;
     e.AppID = AppID;
     if (allData)
     {
         if (!checkLoadState || IsExceptionInfoLoaded)
             e.ExceptionInfo = ExceptionInfo;
         e.IsExceptionInfoLoaded = IsExceptionInfoLoaded;
         if (!checkLoadState || IsMessageLongLoaded)
             e.MessageLong = MessageLong;
         e.IsMessageLongLoaded = IsMessageLongLoaded;
     }
     e.DistinctString = GetDistinctString(true);
     e.IsPersisted = IsPersisted;
     if (preserveState)
         e.IsEntityChanged = IsEntityChanged;
     else
         e.IsEntityChanged = false;
     e.StartAutoUpdating = true;
     return e;
 }
 /// <summary>
 /// Update changes to the current entity compared to an input <paramref name="newdata" /> and set the entity to a proper state for updating.
 /// </summary>
 /// <param name="newdata">The "new" entity acting as the source of the changes, if any.</param>
 /// <returns>
 /// </returns>
 public void UpdateChanges(EventLog newdata)
 {
     int cnt = 0;
     IsEntityChanged = cnt > 0;
 }
 /// <summary>
 /// Merge changes inside entity <paramref name="from" /> to the entity <paramref name="to" />. Any changes in <paramref name="from" /> that is not changed in <paramref name="to" /> is updated inside <paramref name="to" />.
 /// </summary>
 /// <param name="from">The "old" entity acting as merging source.</param>
 /// <param name="to">The "new" entity which inherits changes made in <paramref name="from" />.</param>
 /// <returns>
 /// </returns>
 public static void MergeChanges(EventLog from, EventLog to)
 {
     if (to.IsPersisted)
     {
     }
     else
     {
         to.IsPersisted = from.IsPersisted;
         to.ID = from.ID;
         to.EventLevel = from.EventLevel;
         to.LoggerName = from.LoggerName;
         to.Message_ = from.Message_;
         to.TimeStamp_ = from.TimeStamp_;
         to.AppAgent = from.AppAgent;
         to.AppDomain = from.AppDomain;
         to.CallTrackID = from.CallTrackID;
         to.ExceptionInfo = from.ExceptionInfo;
         to.MessageLong = from.MessageLong;
         to.PageUrl = from.PageUrl;
         to.ReferringUrl = from.ReferringUrl;
         to.ThreadName_ = from.ThreadName_;
         to.ThreadPrincipal = from.ThreadPrincipal;
         to.Username = from.Username;
         to.AppID = from.AppID;
     }
 }
 /// <summary>
 /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) intrinsic identifiers.
 /// </summary>
 /// <param name="other">The entity to be compared to.</param>
 /// <returns>
 ///   The result of comparison.
 /// </returns>
 public bool IsEntityTheSame(EventLog other)
 {
     if (other == null)
         return false;
     else
         return ID == other.ID;
 }              
 /// <summary>
 /// Whether or not the present entity is identitical to <paramref name="other" />, in the sense that they have the same (set of) primary key(s).
 /// </summary>
 /// <param name="other">The entity to be compared to.</param>
 /// <returns>
 ///   The result of comparison.
 /// </returns>
 public bool IsEntityIdentical(EventLog other)
 {
     if (other == null)
         return false;
     if (ID != other.ID)
         return false;
     return true;
 }