Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventSourceSettings"/> class.
        /// </summary>
        /// <param name="name">The friendly event source name.</param>
        /// <param name="eventSourceId">The event source id.</param>
        /// <param name="level">The level.</param>
        /// <param name="matchAnyKeyword">The match any keyword.</param>
        /// <exception cref="ConfigurationException">A validation exception.</exception>
        public EventSourceSettings(string name = null, Guid?eventSourceId = null, EventLevel level = EventLevel.LogAlways, EventKeywords matchAnyKeyword = Keywords.All)
        {
            // If no Id, Name should not be optional so we may derive an Id from it.
            if (!eventSourceId.HasValue || eventSourceId == Guid.Empty)
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    throw new ConfigurationException(Properties.Resources.MissingEventSourceNameAndId);
                }

                eventSourceId = TraceEventSession.GetEventSourceGuidFromName(name);
            }
            else if (!string.IsNullOrWhiteSpace(name))
            {
                // throw and both name & Id specified
                throw new ConfigurationException(Properties.Resources.EventSourceAmbiguityError);
            }

            this.EventSourceId   = eventSourceId.Value;
            this.Name            = name ?? eventSourceId.ToString(); // Set a not null value for later use
            this.Level           = level;
            this.MatchAnyKeyword = matchAnyKeyword;
        }