forked from microsoft/vstest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Event Log Data Collector for Windows OS (microsoft#1002)
* Initial commit for Event Log Data Collector. * Added Tests. * Saving state. * Added Tests. * Added E2E tests. * Added localized resources. * Added entry for Microsoft.TestPlatform.Extensions.EventLogCollector.dll for signing * Removed System.Diagnostics.Debugger.Launch(); * Minor changes. * PR feedback. * PR feedback * PR feedback. * PR feedback. * Merged EventLogContainerContextData and DataCollectorContainer. * PR feedback. * Changed code to have only one EventLog per eventLogName configured. * Added Filter for EventLogEnteries. * Added verification for test case level "Event Log.xml" file. * Fixed failing tests. * PR feedback. * Added more tests, minor changes. * Added logging for EventLogs handling.
- Loading branch information
1 parent
cffd8a8
commit 468d4b2
Showing
46 changed files
with
3,622 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...osoft.TestPlatform.Extensions.EventLogCollector/CollectorNameValueConfigurationManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.TestPlatform.Extensions.EventLogCollector | ||
{ | ||
using System.Collections.Generic; | ||
using System.Xml; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
|
||
/// <summary> | ||
/// Utility class that collectors can use to read name/value configuration information from | ||
/// the XML element sent to them | ||
/// </summary> | ||
internal class CollectorNameValueConfigurationManager | ||
{ | ||
#region Private constants | ||
// Configuration XML constants | ||
private const string SettingNameAttributeName = "name"; | ||
|
||
private const string SettingValueAttributeName = "value"; | ||
|
||
#endregion | ||
|
||
#region Private fields | ||
|
||
/// <summary> | ||
/// The name/value pairs loaded from the configuration XML element | ||
/// </summary> | ||
private IDictionary<string, string> nameValuePairs = new Dictionary<string, string>(); | ||
|
||
#endregion | ||
|
||
#region Constructor | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CollectorNameValueConfigurationManager"/> class. | ||
/// Loads the configuration name/value information from the provided XML element into a dictionary | ||
/// </summary> | ||
/// <param name="configurationElement"> | ||
/// XML element containing the configuration | ||
/// </param> | ||
public CollectorNameValueConfigurationManager(XmlElement configurationElement) | ||
{ | ||
if (configurationElement == null) | ||
{ | ||
// There is no configuration | ||
return; | ||
} | ||
|
||
// Iterate through top-level XML elements within the configuration element and store | ||
// name/value information for elements that have name/value attributes. | ||
foreach (XmlNode settingNode in configurationElement.ChildNodes) | ||
{ | ||
// Skip all non-elements | ||
var settingElement = settingNode as XmlElement; | ||
if (settingElement == null) | ||
{ | ||
continue; | ||
} | ||
|
||
// Get the setting name | ||
string settingName = settingElement.GetAttribute(SettingNameAttributeName); | ||
if (string.IsNullOrWhiteSpace(settingName)) | ||
{ | ||
if (EqtTrace.IsWarningEnabled) | ||
{ | ||
EqtTrace.Warning("Skipping configuration setting due to missing setting name"); | ||
} | ||
|
||
continue; | ||
} | ||
|
||
// Get the setting value | ||
string settingValue = settingElement.GetAttribute(SettingValueAttributeName); | ||
if (string.IsNullOrWhiteSpace(settingValue)) | ||
{ | ||
if (EqtTrace.IsWarningEnabled) | ||
{ | ||
EqtTrace.Warning("Skipping configuration setting '{0}' due to missing value", settingName); | ||
} | ||
|
||
continue; | ||
} | ||
|
||
// Save the name/value pair in the dictionary. Note that duplicate settings are | ||
// overwritten with the last occurrance's value. | ||
if (this.nameValuePairs.ContainsKey(settingName)) | ||
{ | ||
if (EqtTrace.IsVerboseEnabled) | ||
{ | ||
EqtTrace.Verbose( | ||
"Duplicate configuration setting found for '{0}'. Using the last setting.", | ||
settingName); | ||
} | ||
} | ||
|
||
this.nameValuePairs[settingName] = settingValue; | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Public properties | ||
|
||
internal IDictionary<string, string> NameValuePairs => this.nameValuePairs; | ||
|
||
/// <summary> | ||
/// Gets the value of the setting specified by name, or null if it was not found | ||
/// </summary> | ||
/// <param name="name">The setting name</param> | ||
/// <returns>The setting value, or null if the setting was not found</returns> | ||
public string this[string name] | ||
{ | ||
get | ||
{ | ||
if (name == null) | ||
{ | ||
return null; | ||
} | ||
|
||
string settingValue; | ||
this.nameValuePairs.TryGetValue(name, out settingValue); | ||
return settingValue; | ||
} | ||
|
||
set => this.nameValuePairs[name] = value; | ||
} | ||
#endregion | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...lectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogCollectorException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.TestPlatform.Extensions.EventLogCollector | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Private Exception class used for event log exceptions | ||
/// </summary> | ||
internal class EventLogCollectorException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EventLogCollectorException"/> class. | ||
/// </summary> | ||
/// <param name="localizedMessage">the localized exception message</param> | ||
/// <param name="innerException">the inner exception</param> | ||
public EventLogCollectorException(string localizedMessage, Exception innerException) | ||
: base(localizedMessage, innerException) | ||
{ | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/DataCollectors/Microsoft.TestPlatform.Extensions.EventLogCollector/EventLogConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.TestPlatform.Extensions.EventLogCollector | ||
{ | ||
/// <summary> | ||
/// Constants used by Event Log Data Collector. | ||
/// </summary> | ||
internal static class EventLogConstants | ||
{ | ||
// Supported configuration setting names | ||
public const string SettingEventLogs = "EventLogs"; | ||
public const string SettingEventSources = "EventSources"; | ||
public const string SettingEntryTypes = "EntryTypes"; | ||
public const string SettingMaxEntries = "MaxEventLogEntriesToCollect"; | ||
|
||
// default values | ||
public const int DefaultMaxEntries = 50000; | ||
|
||
public const int TypeColumnMaxLength = 64; | ||
public const int SourceColumnMaxLength = 212; | ||
} | ||
} |
Oops, something went wrong.