示例#1
0
        /// <summary>
        /// Called whenever an exception occured in a logged method.
        /// The existing entry may be closed or opened. If it is opened, we first
        /// send the EventCreated event for the error entry before sending
        /// the EventCreated event for the method itself.
        /// We privilegiate here a hierarchical view: the error will be received before the end of the method.
        /// </summary>
        /// <param name="me">Existing entry.</param>
        /// <param name="ex">Exception raised.</param>
        internal void LogMethodError(LogMethodEntry me, Exception ex)
        {
            LogMethodEntryError         l = new LogMethodEntryError(++_nextLSN, me, ex);
            EventHandler <LogEventArgs> h = EventCreated;

            if (me.SetError(l))
            {
                // Entry was opened.
                --_currentDepth;
                if (h != null)
                {
                    // We first send the "Created" event for the error entry.
                    h(_eventSender, l);
                    // We then send the "Created" event for the method entry.
                    h(_eventSender, me);
                }
                else
                {
                    _untrackedErrors.Add(l);
                }
            }
            else
            {
                // Entry is already closed: just send the error entry.
                if (h != null)
                {
                    h(_eventSender, l);
                }
                else
                {
                    _untrackedErrors.Add(l);
                }
            }
            Debug.Assert(!me.IsCreating, "SetError closed the event, whatever its status was.");
        }