Ignore any provider specified via --profile option if they are already specified...
authorSung Yoon Whang <suwhang@microsoft.com>
Tue, 30 Apr 2019 09:14:06 +0000 (02:14 -0700)
committerGitHub <noreply@github.com>
Tue, 30 Apr 2019 09:14:06 +0000 (02:14 -0700)
src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs

index 48316f947d32d95f653704d172432672a277564c..4361d5b643678220ec2e5ecacb769456ff10973c 100644 (file)
@@ -45,8 +45,35 @@ namespace Microsoft.Diagnostics.Tools.Trace
                     throw new ArgumentException($"Invalid profile name: {profile}");
 
                 var providerCollection = Extensions.ToProviders(providers);
+                var profileProviders = new List<Provider>();
+
+                // If user defined a different key/level on the same provider via --providers option that was specified via --profile option,
+                // --providers option takes precedence. Go through the list of providers specified and only add it if it wasn't specified
+                // via --providers options.
                 if (selectedProfile.Providers != null)
-                    providerCollection.AddRange(selectedProfile.Providers);
+                {
+                    foreach (Provider selectedProfileProvider in selectedProfile.Providers)
+                    {
+                        bool shouldAdd = true;
+
+                        foreach (Provider providerCollectionProvider in providerCollection)
+                        {
+                            if (providerCollectionProvider.Name.Equals(selectedProfileProvider.Name))
+                            {
+                                shouldAdd = false;
+                                break;
+                            }
+                        }
+
+                        if (shouldAdd)
+                        {
+                            profileProviders.Add(selectedProfileProvider);
+                        }
+                    }
+                }
+
+                providerCollection.AddRange(profileProviders);
+
                 if (providerCollection.Count <= 0)
                     throw new ArgumentException("No providers were specified to start a trace.");