Beispiel #1
0
        ///////////////////////////////////////////////////////////////////////

        private static void ResetTracePriority()
        {
            lock (syncRoot)
            {
                defaultTracePriority = DefaultTracePriority;
            }
        }
Beispiel #2
0
        ///////////////////////////////////////////////////////////////////////

        private static void ResetTracePriorities()
        {
            lock (syncRoot)
            {
                tracePriorities = DefaultTracePriorities;
            }
        }
Beispiel #3
0
 /// <summary>
 /// Zapíše Warning
 /// </summary>
 /// <param name="priority"></param>
 /// <param name="type"></param>
 /// <param name="method"></param>
 /// <param name="result"></param>
 /// <param name="items"></param>
 public void Warning(TracePriority priority, string type, string method, string result, params string[] items)
 {
     if (App.TraceForPriority(priority))
     {
         this._TraceWrite(null, LEVEL_WARNING, "", type, method, result, false, items);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Zapíše Informaci, ihned
 /// </summary>
 /// <param name="priority"></param>
 /// <param name="type"></param>
 /// <param name="method"></param>
 /// <param name="result"></param>
 /// <param name="items"></param>
 public void InfoNow(TracePriority priority, string type, string method, string result, params string[] items)
 {
     if (App.TraceForPriority(priority))
     {
         this._TraceWrite(null, LEVEL_INFO, "", type, method, result, true, items);
     }
 }
Beispiel #5
0
        ///////////////////////////////////////////////////////////////////////

        private static void SetTracePriority(
            TracePriority priority
            )
        {
            lock (syncRoot)
            {
                defaultTracePriority = priority;
            }
        }
Beispiel #6
0
 /// <summary>
 /// Returns true when specified priority is equal or higher than TracePriority, and request for write to trace has been performed.
 /// </summary>
 /// <param name="priority"></param>
 /// <returns></returns>
 public static bool TraceForPriority(TracePriority priority)
 {
     if (priority == Application.TracePriority.Priority0_None)
     {
         return(false);
     }
     if (priority == Application.TracePriority.Priority9_Allways)
     {
         return(true);
     }
     return((int)priority >= Instance.__TracePriorityInt);
 }
Beispiel #7
0
        ///////////////////////////////////////////////////////////////////////

        public static bool HasFlags(
            TracePriority flags,
            TracePriority hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != TracePriority.None);
            }
        }
Beispiel #8
0
        ///////////////////////////////////////////////////////////////////////

        private static void AdjustTracePriorities(
            TracePriority priority,
            bool enabled
            )
        {
            lock (syncRoot) /* TRANSACTIONAL */
            {
                if (enabled)
                {
                    tracePriorities |= priority;
                }
                else
                {
                    tracePriorities &= ~priority;
                }
            }
        }
Beispiel #9
0
        public static void DebugTrace(
            int?threadId,
            string message,
            string category,
            TracePriority priority
            )
        {
            if (!IsTracePossible())
            {
                return;
            }

            if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */
            {
                return;
            }

            string traceFormat = GetTraceFormat();

            if (traceFormat == null)
            {
                return;
            }

            bool traceDateTime;
            bool tracePriority;
            bool traceAppDomain;
            bool traceInterpreter;
            bool traceThreadId;
            bool traceMethod;

            GetTraceFormatFlags(
                out traceDateTime, out tracePriority, out traceAppDomain,
                out traceInterpreter, out traceThreadId, out traceMethod);

            string methodName = null;

            DebugTraceRaw(FormatOps.TraceOutput(traceFormat,
                                                traceDateTime ? (DateTime?)TimeOps.GetNow() : null,
                                                tracePriority ? (TracePriority?)priority : null,
                                                traceAppDomain ? AppDomainOps.GetCurrent() : null,
                                                traceInterpreter ? Interpreter.GetActive() : null,
                                                traceThreadId ? threadId : null, message, traceMethod,
                                                ref methodName), category, methodName, priority);
        }
Beispiel #10
0
        public static void DebugTrace(
            string message,
            string category,
            TracePriority priority
            )
        {
            if (!IsTracePossible())
            {
                return;
            }

            if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */
            {
                return;
            }

            DebugTrace(
                GlobalState.GetCurrentSystemThreadId(), message, category,
                priority);
        }
Beispiel #11
0
        public static void DebugTrace(
            Exception exception,
            string category,
            TracePriority priority
            )
        {
            if (!IsTracePossible())
            {
                return;
            }

            if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */
            {
                return;
            }

            DebugTrace(
                GlobalState.GetCurrentSystemThreadId(),
                FormatOps.TraceException(exception), category, priority);
        }
Beispiel #12
0
        public static void DebugTrace(
            int?threadId,
            Exception exception,
            string category,
            TracePriority priority
            )
        {
            if (!IsTracePossible())
            {
                return;
            }

            if (!IsTraceEnabled(priority)) /* HACK: *PERF* Bail. */
            {
                return;
            }

            DebugTrace(
                threadId, FormatOps.TraceException(exception), category,
                priority);
        }
Beispiel #13
0
        ///////////////////////////////////////////////////////////////////////

        private static void DebugTraceRaw(
            string message,
            string category,
            string methodName,
            TracePriority priority
            )
        {
            //
            // TODO: Redirect these writes to the active IHost, if any?
            //
            if (IsTraceEnabled(priority, category, methodName))
            {
                try
                {
                    DebugOps.TraceWrite(message, category); /* throw */
                }
                catch
                {
                    // do nothing.
                }
            }
        }
Beispiel #14
0
        ///////////////////////////////////////////////////////////////////////

        //
        // HACK: This is part of a hack that solves a chicken-and-egg problem
        //       with the diagnostic tracing method used by this library.  We
        //       allow tracing to be disabled via an environment variable
        //       and/or the shell command line.  Unfortunately, by the time we
        //       disable tracing, many messages will have typically already
        //       been written to the trace listeners.  To prevent this noise
        //       (that the user wishes to suppress), we internalize the check
        //       (i.e. we do it from inside the core trace method itself) and
        //       initialize this variable [once] with the result of checking
        //       the environment variable.
        //
        private static bool IsTraceEnabled(
            TracePriority priority,
            params string[] categories
            )
        {
            bool result;

            lock (syncRoot) /* TRANSACTIONAL */
            {
                if (isTraceEnabled == null)
                {
                    //
                    // NOTE: Cannot use the GlobalConfiguration.GetValue
                    //       method at this point because that method may
                    //       call into the DebugTrace method (below), which
                    //       calls this method.
                    //
                    if (CommonOps.Environment.DoesVariableExist(
                            EnvVars.NoTrace))
                    {
                        isTraceEnabled = false;
                    }
                    else if (CommonOps.Environment.DoesVariableExist(
                                 EnvVars.Trace))
                    {
                        isTraceEnabled = true;
                    }
                    else
                    {
                        isTraceEnabled = isTraceEnabledByDefault;
                    }
                }

                //
                // NOTE: Determine if tracing is globally enabled or disabled.
                //
                result = (bool)isTraceEnabled;

                //
                // NOTE: If tracing has been globally disabled, do not bother
                //       checking any categories.
                //
                if (result)
                {
                    //
                    // NOTE: The priority flags specified by the caller must
                    //       all be present in the configured trace priority
                    //       flags.
                    //
                    if (!FlagOps.HasFlags(tracePriorities, priority, true))
                    {
                        result = false;
                    }
                    else
                    {
                        //
                        // NOTE: If the caller specified a null category -OR-
                        //       there are no trace categories specifically
                        //       enabled (i.e. all trace categories are
                        //       allowed), always allow the message through.
                        //
                        if ((categories != null) &&
                            (categories.Length > 0) &&
                            (traceCategories != null) &&
                            (traceCategories.Count > 0))
                        {
                            //
                            // NOTE: At this point, at least one of the
                            //       specified trace categories, if any,
                            //       must exist in the dictionary and its
                            //       associated value must be non-zero;
                            //       otherwise, the trace message is not
                            //       allowed through.
                            //
                            bool found = false;

                            foreach (string category in categories)
                            {
                                if (category == null)
                                {
                                    continue;
                                }

                                int value;

                                if (traceCategories.TryGetValue(
                                        category, out value) &&
                                    (value != 0))
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (!found)
                            {
                                result = false;
                            }
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #15
0
        /// <summary>
        /// Otevře Scope (dá Begin), ihned, jehož Dispose zapíše párový End
        /// </summary>
        /// <param name="priority"></param>
        /// <param name="type"></param>
        /// <param name="method"></param>
        /// <param name="result"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        public ITraceScope ScopeNow(TracePriority priority, string type, string method, string result, params string[] items)
        {
            bool isReal = App.TraceForPriority(priority);

            return(TraceScope.GetScope(this, true, isReal, type, method, result, items));
        }