Example #1
0
        public TraceFilter(string typeFilter, MessageTypes msgTypeFilter, Level levelFilter, TraceFilter next)
        {
            if (String.IsNullOrEmpty(typeFilter))
            {
                throw new ArgumentException("typeFilter was null or empty");
            }

            myFilter        = typeFilter;
            Next            = next;
            myMsgTypeFilter = msgTypeFilter;
            myLevelFilter   = levelFilter;

            string[] parts = typeFilter.Trim().ToLower().Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            myFilterHashes = new int[parts.Length];
            Debug.Assert(parts.Length > 0, "Type filter parts should be > 0");
            for (int i = 0; i < parts.Length; i++)
            {
                if (parts[i] == "*")
                {
                    myFilterHashes[i] = MATCHANY;
                }
                else
                {
                    myFilterHashes[i] = parts[i].GetHashCode();
                }
            }
        }
Example #2
0
        internal TracerConfig(string cfg)
        {
            if (String.IsNullOrEmpty(cfg))
            {
                return;
            }

            TraceSource source = new TraceSource(TraceEnvVarName, SourceLevels.All);

            myListeners = source.Listeners;

            TraceCfgParser parser      = new TraceCfgParser(cfg);
            TraceListener  newListener = parser.OutDevice;

            this.myFilters    = parser.Filters;
            this.myNotFilters = parser.NotFilters;

            if (newListener != null)
            {
                // when the App.config _Trace source should be used we do not replace
                // anything
                if (!parser.UseAppConfigListeners)
                {
                    myListeners.Clear();
                    myListeners.Add(newListener);
                }
            }
            else
            {
                myListeners = null;
            }
        }
Example #3
0
        /// <summary>
        /// Format string is of the form
        /// outDevice; type flag1+flag2+...;type flags; ...
        /// where flags are a combination of trace markers
        /// </summary>
        /// <param name="config"></param>
        public TraceCfgParser(string config)
        {
            if (String.IsNullOrEmpty(config))
            {
                return;
            }

            string [] parts = config.Split(new char [] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                              .Select((str) => str.Trim())
                              .ToArray();

            foreach (KeyValuePair <string, string []> filter in GetFilters(parts, 1).Reverse())
            {
                string typeName     = filter.Key.TrimStart(new char[] { '!' });
                bool   bIsNotFilter = filter.Key.IndexOf('!') == 0;

                KeyValuePair <Level, MessageTypes> levelAndMsgFilter = ParseMsgTypeFilter(filter.Value);

                TraceFilter curFilterInstance = new TraceFilter(typeName,
                                                                levelAndMsgFilter.Value,
                                                                levelAndMsgFilter.Key,
                                                                bIsNotFilter ? NotFilters : Filters);

                if (bIsNotFilter)
                {
                    NotFilters = curFilterInstance;
                }
                else
                {
                    Filters = curFilterInstance;
                }
            }

            if (parts.Length > 0)
            {
                OpenOutputDevice(parts[0].ToLower());
            }

            // when only output device was configured or wrong mask was entere we enable full tracing
            // by default
            if (this.Filters == null)
            {
                this.Filters = new TraceFilterMatchAll();
            }

            if (bHasError == true)
            {
                InternalError.PrintHelp();
            }
        }