Esempio n. 1
0
        /// <summary>
        ///     Writes the specified entry to the log.
        /// </summary>
        /// <param name="entry">The entry to be written.</param>
        /// <remarks>
        ///     All overloads of Write ultimately call this method.
        /// </remarks>
        public static void Write(LogEntry entry)
        {
            var handler = EntryPosted;

            if (handler == null)
            {
                return;
            }

            // prevent re-entrancy
            if (entry.HasBeenPosted)
            {
                return;
            }
            entry.HasBeenPosted = true;

            foreach (EventHandler <InstrumentationEventArgs> subscriber in EntryPosted.GetInvocationList())
            {
                try
                {
                    subscriber(typeof(Log), new InstrumentationEventArgs(entry));
                }
                catch (Exception exceptionFromHandler)
                {
                    exceptionFromHandler.RaiseErrorEvent();
                    if (exceptionFromHandler.ShouldThrow())
                    {
                        throw;
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Unsubscribes all subscribers to the <see cref="Log.EntryPosted" /> event.
        /// </summary>
        internal static void UnsubscribeAllFromEntryPosted()
        {
            var handler = EntryPosted;

            if (handler == null)
            {
                return;
            }

            var subscribers = EntryPosted.GetInvocationList();

            foreach (var d in subscribers)
            {
                EntryPosted -= (d as EventHandler <InstrumentationEventArgs>);
            }
        }