Beispiel #1
0
        public static void Trace(TraceComponent component, string log)
        {
            // Check the global environment variable named "DEBUGGING_ENABLED" to see if it's set.
            string env = Environment.GetEnvironmentVariable("DEBUGGING_ENABLED");
            bool   isDebuggingEnabled = env == "y" || env == "true" || env == "yes";

            if (!isDebuggingEnabled)
            {
                // Trace disabled globally.
                return;
            }

            // Trace components can be individually enabled or disabled.
            // Based on the capitalized enumeration name, check to see if that environment variable is enabled.
            // If the trace isn't attached to a specific component, it'll be displayed every time (so long as the global setting is on)
            bool componentEnabled = true;

            if (component != TraceComponent.None)
            {
                string componentName = Enum.GetName(typeof(TraceComponent), component)?.ToUpper();
                env = Environment.GetEnvironmentVariable("DEBUGGING_COMPONENT_ENABLED_" + componentName);
                componentEnabled = env == "y" || env == "true" || env == "yes";
            }

            // If the component is enabled, output the trace.
            if (componentEnabled)
            {
                string componentName = component == TraceComponent.None ? string.Empty : component.ToString();
                Console.WriteLine(componentName + " -- " + log);
            }
        }
Beispiel #2
0
 public Tracer(TraceComponent component)
 {
     _componentName = component.ToString();
 }