Exemplo n.º 1
0
        private static void ExtendLogEntry(
            LogEntry logEntry,
            IEnumerable <Func <LogEntry, object> > extenders)
        {
            foreach (var extend in extenders)
            {
                var ext = extend(logEntry);

                var paramsExt = ext as Params;
                if (paramsExt != null)
                {
                    if (logEntry.AnonymousMethodInfo == null)
                    {
                        logEntry.AnonymousMethodInfo = paramsExt.ParamsAccessor.GetAnonymousMethodInfo();
                    }

                    if (Extension <Params> .IsEnabledFor(logEntry.CallingType))
                    {
                        logEntry.SetExtension(ext);
                    }
                }
                else
                {
                    logEntry.SetExtension(ext);
                }
            }
        }
Exemplo n.º 2
0
        private void ExtendLogEntry(LogEntry e)
        {
            foreach (var extensionGetter in extensionGetters)
            {
                var ext = extensionGetter.Value(e);

                var paramsExt = ext as Params;
                if (paramsExt != null)
                {
                    if (e.AnonymousMethodInfo == null)
                    {
                        e.AnonymousMethodInfo = paramsExt.ParamsAccessor.GetAnonymousMethodInfo();
                    }

                    if (Extension <Params> .IsEnabledFor(e.CallingType))
                    {
                        e.SetExtension(ext);
                    }
                }
                else
                {
                    e.SetExtension(ext);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///   Indicates to the log that execution is entering a region.
        /// </summary>
        /// <typeparam name = "T">The <see cref = "Type" /> of the anonymous type of <paramref name = "paramsAccessor" /> used to enclose parameters to be logged at this boundary.</typeparam>
        /// <param name = "paramsAccessor">An anonymous type enclosing parameters to be logged.</param>
        /// <returns>An <see cref = "ILogActivity" />.</returns>
        public ILogActivity Enter <T>(Func <T> paramsAccessor, bool requireConfirm = false) where T : class
        {
            Func <Func <T>, ILogActivity> enter = action =>
            {
                if (!Extension <Boundaries> .IsEnabledFor(
                        action.GetAnonymousMethodInfo().EnclosingType))
                {
                    return(NullLogActivity.Instance);
                }
                var entry = new LogEntry <T>(action);
                ExtendLogEntry(entry);
                return(new LogActivity(entry, requireConfirm));
            };

            return(enter.InvokeSafely(paramsAccessor));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Indicates to the log that execution is entering a region.
        /// </summary>
        /// <param name="magicBarbell">An empty anonymous method which will not be called, i.e.: ( ) => { }</param>
        /// <returns>An <see cref="ILogActivity"/>.</returns>
        /// <remarks>The anonymous method is used to resolve the enclosing method and type without the use of a more expensive <see cref="StackFrame" />.</remarks>
        public ILogActivity Enter(Action magicBarbell)
        {
            Func <Action, ILogActivity> enter = action =>
            {
                AnonymousMethodInfo anonymousMethodInfo = action.GetAnonymousMethodInfo();
                if (!Extension <Boundaries> .IsEnabledFor(
                        anonymousMethodInfo.EnclosingType))
                {
                    return(NullLogActivity.Instance);
                }
                var entry = new LogEntry(anonymousMethodInfo);
                ExtendLogEntry(entry);
                return(new LogActivity(entry));
            };

            return(enter.InvokeSafely(magicBarbell));
        }