Skip to content

Commit

Permalink
Simplify calls to EqtTrace logger (#3351)
Browse files Browse the repository at this point in the history
Co-authored-by: Amaury Levé <[email protected]>
  • Loading branch information
Evangelink and Evangelink authored Feb 11, 2022
1 parent 0d2c63d commit 8814a6d
Show file tree
Hide file tree
Showing 74 changed files with 369 additions and 1,192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,25 @@ public CollectorNameValueConfigurationManager(XmlElement configurationElement)
string settingName = settingElement.GetAttribute(SettingNameAttributeName);
if (string.IsNullOrWhiteSpace(settingName))
{
if (EqtTrace.IsWarningEnabled)
{
EqtTrace.Warning("Skipping configuration setting due to missing setting name");
}

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);
}

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 occurrence's value.
if (NameValuePairs.ContainsKey(settingName))
{
if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(
"Duplicate configuration setting found for '{0}'. Using the last setting.",
settingName);
}
EqtTrace.Verbose(
"Duplicate configuration setting found for '{0}'. Using the last setting.",
settingName);
}

NameValuePairs[settingName] = settingValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,11 @@ public void OnEventLogEntryWritten(object source, EntryWrittenEventArgs e)

if (mostRecentIndexInLog < NextEntryIndexToCollect - 1)
{
if (EqtTrace.IsWarningEnabled)
{
EqtTrace.Warning(
string.Format(
CultureInfo.InvariantCulture,
"EventLogDataContainer: OnEventLogEntryWritten: Handling clearing of log (mostRecentIndexInLog < eventLogContainer.NextEntryIndex): firstIndexInLog: {0}:, mostRecentIndexInLog: {1}, NextEntryIndex: {2}",
firstIndexInLog,
mostRecentIndexInLog,
NextEntryIndexToCollect));
}
EqtTrace.Warning(
"EventLogDataContainer: OnEventLogEntryWritten: Handling clearing of log (mostRecentIndexInLog < eventLogContainer.NextEntryIndex): firstIndexInLog: {0}:, mostRecentIndexInLog: {1}, NextEntryIndex: {2}",
firstIndexInLog,
mostRecentIndexInLog,
NextEntryIndexToCollect);

// Send warning; event log must have been cleared.
_dataCollectionLogger.LogWarning(
Expand Down Expand Up @@ -190,16 +185,11 @@ public void OnEventLogEntryWritten(object source, EntryWrittenEventArgs e)
{
EventLogEntries.Add(nextEntry);

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(
string.Format(
CultureInfo.InvariantCulture,
"EventLogDataContainer.OnEventLogEntryWritten() add event with Id {0} from position {1} in the current {2} log",
nextEntry.Index,
nextEntryIndexInCurrentLog,
EventLog.Log));
}
EqtTrace.Verbose(
"EventLogDataContainer.OnEventLogEntryWritten() add event with Id {0} from position {1} in the current {2} log",
nextEntry.Index,
nextEntryIndexInCurrentLog,
EventLog.Log);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,28 +278,20 @@ internal string WriteEventLogs(List<EventLogEntry> eventLogEntries, int maxLogEn

stopwatch.Stop();

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(
string.Format(
CultureInfo.InvariantCulture,
"EventLogDataContainer: Wrote {0} event log entries to file '{1}' in {2} seconds",
eventLogEntries.Count,
eventLogPath,
stopwatch.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture)));
}
EqtTrace.Verbose(
"EventLogDataContainer: Wrote {0} event log entries to file '{1}' in {2} seconds",
eventLogEntries.Count,
eventLogPath,
stopwatch.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture));

// Write the event log file
FileTransferInformation fileTransferInformation =
new(dataCollectionContext, eventLogPath, true, _fileHelper);
_dataSink.SendFileAsync(fileTransferInformation);

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(
"EventLogDataContainer: Event log successfully sent for data collection context '{0}'.",
dataCollectionContext.ToString());
}
EqtTrace.Verbose(
"EventLogDataContainer: Event log successfully sent for data collection context '{0}'.",
dataCollectionContext.ToString());

return eventLogPath;
}
Expand Down Expand Up @@ -350,10 +342,7 @@ private void OnSessionStart(object sender, SessionStartEventArgs e)
ValidateArg.NotNull(e, "SessionStartEventArgs");
ValidateArg.NotNull(e.Context, "SessionStartEventArgs.Context");

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("EventLogDataCollector: SessionStart received");
}
EqtTrace.Verbose("EventLogDataCollector: SessionStart received");

StartCollectionForContext(e.Context, true);
}
Expand All @@ -363,10 +352,7 @@ private void OnSessionEnd(object sender, SessionEndEventArgs e)
ValidateArg.NotNull(e, "SessionEndEventArgs");
ValidateArg.NotNull(e.Context, "SessionEndEventArgs.Context");

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("EventLogDataCollector: SessionEnd received");
}
EqtTrace.Verbose("EventLogDataCollector: SessionEnd received");

WriteCollectedEventLogEntries(e.Context, true, TimeSpan.MaxValue, DateTime.UtcNow);
}
Expand All @@ -382,10 +368,7 @@ private void OnTestCaseStart(object sender, TestCaseStartEventArgs e)
ValidateArg.NotNull(e.Context.TestExecId, "TestCaseStartEventArgs.Context.HasTestCase");
}

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose("EventLogDataCollector: TestCaseStart received for test '{0}'.", e.TestCaseName);
}
EqtTrace.Verbose("EventLogDataCollector: TestCaseStart received for test '{0}'.", e.TestCaseName);

StartCollectionForContext(e.Context, false);
}
Expand All @@ -397,13 +380,10 @@ private void OnTestCaseEnd(object sender, TestCaseEndEventArgs e)
Debug.Assert(e.Context != null, "Context is null");
Debug.Assert(e.Context.HasTestCase, "Context is not for a test case");

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(
"EventLogDataCollector: TestCaseEnd received for test '{0}' with Test Outcome: {1}.",
e.TestCaseName,
e.TestOutcome);
}
EqtTrace.Verbose(
"EventLogDataCollector: TestCaseEnd received for test '{0}' with Test Outcome: {1}.",
e.TestCaseName,
e.TestOutcome);

WriteCollectedEventLogEntries(e.Context, false, TimeSpan.MaxValue, DateTime.UtcNow);
}
Expand Down Expand Up @@ -487,11 +467,8 @@ private void ConfigureEventLogNames(CollectorNameValueConfigurationManager colle
if (eventLogs != null)
{
EventLogNames = ParseCommaSeparatedList(eventLogs);
if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(
"EventLogDataCollector configuration: " + EventLogConstants.SettingEventLogs + "=" + eventLogs);
}
EqtTrace.Verbose(
"EventLogDataCollector configuration: " + EventLogConstants.SettingEventLogs + "=" + eventLogs);
}
else
{
Expand All @@ -517,13 +494,7 @@ private void ConfigureEventLogNames(CollectorNameValueConfigurationManager colle
_eventLogContainerMap.Add(eventLogName, eventLogContainer);
}

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(string.Format(
CultureInfo.InvariantCulture,
"EventLogDataCollector: Created EventSource '{0}'",
eventLogName));
}
EqtTrace.Verbose("EventLogDataCollector: Created EventSource '{0}'", eventLogName);
}
catch (Exception ex)
{
Expand All @@ -540,12 +511,9 @@ private void ConfigureEventSources(CollectorNameValueConfigurationManager collec
if (!string.IsNullOrEmpty(eventSourcesStr))
{
EventSources = ParseCommaSeparatedList(eventSourcesStr);
if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(
"EventLogDataCollector configuration: " + EventLogConstants.SettingEventSources + "="
+ EventSources);
}
EqtTrace.Verbose(
"EventLogDataCollector configuration: " + EventLogConstants.SettingEventSources + "="
+ EventSources);
}
}

Expand All @@ -561,12 +529,9 @@ private void ConfigureEntryTypes(CollectorNameValueConfigurationManager collecto
(EventLogEntryType)Enum.Parse(typeof(EventLogEntryType), entryTypestring, true));
}

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(
"EventLogDataCollector configuration: " + EventLogConstants.SettingEntryTypes + "="
+ EntryTypes);
}
EqtTrace.Verbose(
"EventLogDataCollector configuration: " + EventLogConstants.SettingEntryTypes + "="
+ EntryTypes);
}
else
{
Expand Down Expand Up @@ -596,12 +561,9 @@ private void ConfigureMaxEntries(CollectorNameValueConfigurationManager collecto
MaxEntries = EventLogConstants.DefaultMaxEntries;
}

if (EqtTrace.IsVerboseEnabled)
{
EqtTrace.Verbose(
"EventLogDataCollector configuration: " + EventLogConstants.SettingMaxEntries + "="
+ MaxEntries);
}
EqtTrace.Verbose(
"EventLogDataCollector configuration: " + EventLogConstants.SettingMaxEntries + "="
+ MaxEntries);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ public TestRunAttachmentsProcessingEventsHandler(ICommunicationManager communica
/// <inheritdoc/>
public void HandleTestRunAttachmentsProcessingComplete(TestRunAttachmentsProcessingCompleteEventArgs attachmentsProcessingCompleteEventArgs, IEnumerable<AttachmentSet> lastChunk)
{
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("Test run attachments processing completed.");
}
EqtTrace.Info("Test run attachments processing completed.");

var payload = new TestRunAttachmentsProcessingCompletePayload()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ private void ProcessRequests(ITestRequestManager testRequestManager)
{
var message = _communicationManager.ReceiveMessage();

if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("DesignModeClient.ProcessRequests: Processing Message: {0}", message);
}
EqtTrace.Info("DesignModeClient.ProcessRequests: Processing Message: {0}", message);

switch (message.MessageType)
{
Expand Down
Loading

0 comments on commit 8814a6d

Please sign in to comment.