private void ConfigureMaxEntries(CollectorNameValueConfigurationManager collectorNameValueConfigurationManager) { string maxEntriesstring = collectorNameValueConfigurationManager[EventLogConstants.SettingMaxEntries]; if (maxEntriesstring != null) { try { this.maxEntries = int.Parse(maxEntriesstring, CultureInfo.InvariantCulture); // A negative or 0 value means no maximum if (this.maxEntries <= 0) { this.maxEntries = int.MaxValue; } } catch (FormatException) { this.maxEntries = EventLogConstants.DefaultMaxEntries; } if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose( "EventLogDataCollector configuration: " + EventLogConstants.SettingMaxEntries + "=" + this.maxEntries); } } else { this.maxEntries = EventLogConstants.DefaultMaxEntries; } }
private void ConfigureEntryTypes(CollectorNameValueConfigurationManager collectorNameValueConfigurationManager) { this.entryTypes = new HashSet <EventLogEntryType>(); string entryTypesStr = collectorNameValueConfigurationManager[EventLogConstants.SettingEntryTypes]; if (entryTypesStr != null) { foreach (string entryTypestring in ParseCommaSeparatedList(entryTypesStr)) { this.entryTypes.Add( (EventLogEntryType)Enum.Parse(typeof(EventLogEntryType), entryTypestring, true)); } if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose( "EventLogDataCollector configuration: " + EventLogConstants.SettingEntryTypes + "=" + this.entryTypes); } } else { this.entryTypes.Add(EventLogEntryType.Error); this.entryTypes.Add(EventLogEntryType.Warning); this.entryTypes.Add(EventLogEntryType.FailureAudit); } }
/// <summary> /// Initializes the data collector /// </summary> /// <param name="configurationElement"> /// The XML element containing configuration information for the data collector. Currently, /// this data collector does not have any configuration, so we ignore this parameter. /// </param> /// <param name="events"> /// Object containing the execution events the data collector registers for /// </param> /// <param name="dataSink">The sink used by the data collector to send its data</param> /// <param name="logger"> /// Used by the data collector to send warnings, errors, or other messages /// </param> /// <param name="dataCollectionEnvironmentContext">Provides contextual information about the agent environment</param> public override void Initialize( XmlElement configurationElement, DataCollectionEvents events, DataCollectionSink dataSink, DataCollectionLogger logger, DataCollectionEnvironmentContext dataCollectionEnvironmentContext) { ValidateArg.NotNull(events, nameof(events)); ValidateArg.NotNull(dataSink, nameof(dataSink)); ValidateArg.NotNull(logger, nameof(logger)); this.events = events; this.dataSink = dataSink; this.logger = logger; this.dataCollectorContext = dataCollectionEnvironmentContext.SessionDataCollectionContext; // Load the configuration CollectorNameValueConfigurationManager nameValueSettings = new CollectorNameValueConfigurationManager(configurationElement); // Apply the configuration this.ConfigureEventSources(nameValueSettings); this.ConfigureEntryTypes(nameValueSettings); this.ConfigureMaxEntries(nameValueSettings); this.ConfigureEventLogNames(nameValueSettings); // Register for events events.SessionStart += this.sessionStartEventHandler; events.SessionEnd += this.sessionEndEventHandler; events.TestCaseStart += this.testCaseStartEventHandler; events.TestCaseEnd += this.testCaseEndEventHandler; }
private void ConfigureEventLogNames(CollectorNameValueConfigurationManager collectorNameValueConfigurationManager) { this.eventLogNames = new HashSet <string>(); string eventLogs = collectorNameValueConfigurationManager[EventLogConstants.SettingEventLogs]; if (eventLogs != null) { this.eventLogNames = ParseCommaSeparatedList(eventLogs); if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose( "EventLogDataCollector configuration: " + EventLogConstants.SettingEventLogs + "=" + eventLogs); } } else { // Default to collecting these standard logs this.eventLogNames.Add("System"); this.eventLogNames.Add("Security"); this.eventLogNames.Add("Application"); } foreach (string eventLogName in this.eventLogNames) { try { // Create an EventLog object and add it to the eventLogContext if one does not already exist if (!this.eventLogContainerMap.ContainsKey(eventLogName)) { IEventLogContainer eventLogContainer = new EventLogContainer( eventLogName, this.eventSources, this.entryTypes, int.MaxValue, this.logger, this.dataCollectorContext); this.eventLogContainerMap.Add(eventLogName, eventLogContainer); } if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose(string.Format( CultureInfo.InvariantCulture, "EventLogDataCollector: Created EventSource '{0}'", eventLogName)); } } catch (Exception ex) { this.logger.LogError( null, new EventLogCollectorException(string.Format(CultureInfo.InvariantCulture, Resource.ReadError, eventLogName, Environment.MachineName), ex)); } } }
private void ConfigureEventSources(CollectorNameValueConfigurationManager collectorNameValueConfigurationManager) { string eventSourcesStr = collectorNameValueConfigurationManager[EventLogConstants.SettingEventSources]; if (!string.IsNullOrEmpty(eventSourcesStr)) { this.eventSources = ParseCommaSeparatedList(eventSourcesStr); if (EqtTrace.IsVerboseEnabled) { EqtTrace.Verbose( "EventLogDataCollector configuration: " + EventLogConstants.SettingEventSources + "=" + this.eventSources); } } }