/// <summary> /// Loads the specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="monitorChanges">If set to <c>true</c> monitor file changes.</param> /// <param name="createSinks">If set to <c>true</c> [create sinks].</param> /// <returns> /// The loaded <see cref="TraceEventServiceConfiguration" /> instance. /// </returns> /// <exception cref="ConfigurationException">All the validation errors detected when opening the file.</exception> public static TraceEventServiceConfiguration Load(string fileName, bool monitorChanges = false, bool createSinks = true) { var configReader = new ConfigurationReader(fileName); ConfigurationElement configElement = configReader.Read(); var serviceSettings = new TraceEventServiceSettings() { SessionNamePrefix = configElement.TraceEventService.SessionNamePrefix }; var sinkSettings = new List <SinkSettings>(); foreach (var element in configElement.SinkConfigurationElements) { var eventSources = element.EventSources.Select(e => new EventSourceSettings(e.Name, e.EventId, e.Level, e.MatchAnyKeyword)); var sink = createSinks ? new SinkSettings(element.Name, element.SinkPromise.Value, eventSources) : new SinkSettings(element.Name, element.SinkPromise, eventSources); sink.SinkConfiguration = element.SinkConfiguration; sinkSettings.Add(sink); } var configuration = new TraceEventServiceConfiguration(sinkSettings, serviceSettings); if (monitorChanges) { configuration.StartConfigurationWatcher(configReader.File); } return(configuration); }
public TraceEventServiceWorker(SinkSettings sinkSettings, TraceEventServiceSettings serviceSettings) { Guard.ArgumentNotNull(sinkSettings, "sinkSettings"); Guard.ArgumentNotNull(serviceSettings, "serviceSettings"); this.sink = sinkSettings.Sink; this.eventSources = new List<EventSourceSettings>(sinkSettings.EventSources); this.sessionName = serviceSettings.SessionNamePrefix + "-" + sinkSettings.Name; this.Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="TraceEventServiceConfiguration" /> class. /// </summary> /// <param name="sinkSettings">The sink settings.</param> /// <param name="settings">The settings.</param> /// <exception cref="ArgumentNotNull">The EventSources.</exception> public TraceEventServiceConfiguration(IEnumerable <SinkSettings> sinkSettings = null, TraceEventServiceSettings settings = null) { this.sinkSettings = new ObservableCollection <SinkSettings>(sinkSettings ?? Enumerable.Empty <SinkSettings>()); this.settings = settings ?? new TraceEventServiceSettings(); // Validate duplicate sinks if (this.sinkSettings.GroupBy(i => i.Name).Any(g => g.Count() > 1)) { throw new ConfigurationException(Properties.Resources.DuplicateSinksError); } }
/// <summary> /// Initializes a new instance of the <see cref="TraceEventServiceConfiguration" /> class. /// </summary> /// <param name="sinkSettings">The sink settings.</param> /// <param name="settings">The settings.</param> /// <exception cref="ConfigurationException">The EventSources.</exception> public TraceEventServiceConfiguration(IEnumerable<SinkSettings> sinkSettings = null, TraceEventServiceSettings settings = null) { this.sinkSettings = new ObservableCollection<SinkSettings>(sinkSettings ?? Enumerable.Empty<SinkSettings>()); this.settings = settings ?? new TraceEventServiceSettings(); // Validate duplicate sinks if (this.sinkSettings.GroupBy(i => i.Name).Any(g => g.Count() > 1)) { throw new ConfigurationException(Properties.Resources.DuplicateSinksError); } }
/// <summary> /// Determines whether the specified <see cref="TraceEventServiceSettings" /> is equal to the current <see cref="TraceEventServiceSettings" />. /// </summary> /// <param name="obj">The instance to compare with the current instance.</param> /// <returns> /// True if the specified instance is equal to the current instance; otherwise, false. /// </returns> public override bool Equals(object obj) { // Check for null values and compare run-time types. if (obj == null || GetType() != obj.GetType()) { return(false); } TraceEventServiceSettings s = (TraceEventServiceSettings)obj; return(this.SessionNamePrefix == s.SessionNamePrefix); }
/// <summary> /// Loads the specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="monitorChanges">If set to <c>true</c> monitor file changes.</param> /// <param name="createSinks">If set to <c>true</c> [create sinks].</param> /// <returns> /// The loaded <see cref="TraceEventServiceConfiguration" /> instance. /// </returns> /// <exception cref="ConfigurationException">All the validation errors detected when opening the file.</exception> public static TraceEventServiceConfiguration Load(string fileName, bool monitorChanges = false, bool createSinks = true) { var configReader = new ConfigurationReader(fileName); ConfigurationElement configElement = configReader.Read(); var serviceSettings = new TraceEventServiceSettings { SessionNamePrefix = configElement.TraceEventService.SessionNamePrefix }; var sinkSettings = new List<SinkSettings>(); foreach (var element in configElement.SinkConfigurationElements) { var eventSources = element.EventSources.Select( e => new EventSourceSettings( e.Name, e.EventId, e.Level, e.MatchAnyKeyword, e.Arguments.Select(a => new KeyValuePair<string, string>(a.Key, a.Value)), e.ProcessNameFilters.Select(p => p.Name))); var sink = createSinks ? new SinkSettings(element.Name, element.SinkPromise.Value, eventSources) : new SinkSettings(element.Name, element.SinkPromise, eventSources); sink.SinkConfiguration = element.SinkConfiguration; sinkSettings.Add(sink); } var configuration = new TraceEventServiceConfiguration(sinkSettings, serviceSettings); if (monitorChanges) { configuration.StartConfigurationWatcher(configReader.File); } return configuration; }
protected override void Given() { this.sinkSettings = new SinkSettings("test", new InMemoryEventListener(), new[] { new EventSourceSettings("Test") }); this.traceEventServiceSettings = new TraceEventServiceSettings(); }
public void when_creating_instance_with_default_values() { var sut = new TraceEventServiceSettings(); Assert.IsTrue(sut.SessionNamePrefix.StartsWith(Constants.DefaultSessionNamePrefix)); }