private IEnumerable <KeyValuePair <string, string[]> > GetFilters(string[] filters, int nSkip)
        {
            foreach (var current in filters.Skip(nSkip))
            {
                var filterParts = current.Split(new[] { '+', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (filterParts.Length < 2)
                {
                    this.bHasError = true;
                    InternalError.Print("The configuration string {0} did have an unmatched type severity or level filter part: {0}", current);
                }

                yield return(new KeyValuePair <string, string[]>(filterParts[0], filterParts.Skip(1).ToArray()));
            }
        }
        /// <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;
            }

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

            foreach (var filter in this.GetFilters(parts, 1).Reverse())
            {
                var typeName     = filter.Key.TrimStart('!');
                var bIsNotFilter = filter.Key.IndexOf('!') == 0;

                var levelAndMsgFilter = this.ParseMsgTypeFilter(filter.Value);

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

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

            if (parts.Length > 0)
            {
                this.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 (this.bHasError)
            {
                InternalError.PrintHelp();
            }
        }
        private void OpenOutputDevice(string outDevice)
        {
            var parts = outDevice.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            var deviceName   = parts[0];
            var deviceConfig = string.Join(" ", parts.Skip(1).ToArray());

            switch (deviceName)
            {
            case "file":
                if (deviceConfig == "")
                {
                    deviceConfig = DefaultTraceFileBaseName;
                }
                this.OutDevice = new TextWriterTraceListener(CreateTraceFile(deviceConfig));
                break;

            case "debugoutput":
                this.OutDevice = new DefaultTraceListener();
                break;

            case "console":
                this.OutDevice = new ConsoleTraceListener();
                break;

            case "null":
                this.OutDevice = new NullTraceListener();
                break;

            case "default":
                this.UseAppConfigListeners = true;
                this.OutDevice             = new NullTraceListener();
                break;

            default:
                InternalError.Print("The trace output device {0} is not supported.", outDevice);
                this.bHasError = true;
                break;
            }
        }