/// <summary>
 /// Applies the thread context stored earlier
 /// </summary>
 /// <param name="callerThreadContext"></param>
 public static void Apply(CallerThreadContext callerThreadContext)
 {
     if (callerThreadContext == null)
     {
         throw new ArgumentNullException("callerThreadContext");
     }
     if ((callerThreadContext._callContext != null) && (setLogicalCallContextMethodInfo != null))
     {
         setLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, new object[] { callerThreadContext._callContext });
     }
     if (callerThreadContext._httpContext != null)
     {
         CallContext.SetData(HttpContextSlotName, callerThreadContext._httpContext);
     }
 }
        /// <summary>
        /// Captures the current thread context
        /// </summary>
        /// <returns></returns>
        public static CallerThreadContext Capture(bool captureCallContext, bool captureHttpContext)
        {
            CallerThreadContext context = new CallerThreadContext();

            if (captureCallContext && (getLogicalCallContextMethodInfo != null))
            {
                context._callContext = (LogicalCallContext)getLogicalCallContextMethodInfo.Invoke(Thread.CurrentThread, null);
                if (context._callContext != null)
                {
                    context._callContext = (LogicalCallContext)context._callContext.Clone();
                }
            }
            if (captureHttpContext && (HttpContext.Current != null))
            {
                context._httpContext = HttpContext.Current;
            }
            return(context);
        }