Skip to content

Commit bb009af

Browse files
authored
Update monitor cmdlet warning message (#17129)
* update monitor cmdlet warning message * update the changelog.md * update logic * update some logic
1 parent be4b08d commit bb009af

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/Monitor/Monitor/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020

2121
## Upcoming Release
22+
* Fixed an issue where users could not correctly ignore warning messages after setting environment variables [#17013]
2223

2324
## Version 3.0.0
2425
* Added new properties EventName, Category, ResourceProviderName, OperationName, Status, SubStatus with type string as output for command Get-AzLog [#15833]

src/Monitor/Monitor/MonitorCmdletBase.cs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,24 @@ protected string GetCmdletName()
6060
/// <param name="withTimeStamp">true if the message should include a timestamp, false (default) it no timestamp should be included</param>
6161
protected void WriteIdentifiedWarning(string cmdletName, string topic, string message, bool withTimeStamp = false)
6262
{
63-
string formattedMessage = string.Format(
64-
CultureInfo.InvariantCulture,
65-
"[{0}] {1}: {2}",
66-
cmdletName,
67-
topic,
68-
message);
69-
70-
if (withTimeStamp)
71-
{
72-
WriteWarningWithTimestamp(formattedMessage);
73-
}
74-
else
63+
string supressWarningOrErrorValue = System.Environment.GetEnvironmentVariable(BreakingChangeAttributeHelper.SUPPRESS_ERROR_OR_WARNING_MESSAGE_ENV_VARIABLE_NAME);
64+
bool supressWarningOrError;
65+
Boolean.TryParse(supressWarningOrErrorValue, out supressWarningOrError);
66+
if (!supressWarningOrError)
7567
{
76-
WriteWarning(formattedMessage);
68+
string formattedMessage = string.Format(
69+
CultureInfo.InvariantCulture, "{0}{1}{2}",
70+
string.IsNullOrEmpty(cmdletName) ? cmdletName : "[" + cmdletName + "] ",
71+
string.IsNullOrEmpty(topic) ? topic : topic + ": ",
72+
message);
73+
if (withTimeStamp)
74+
{
75+
WriteWarningWithTimestamp(formattedMessage);
76+
}
77+
else
78+
{
79+
WriteWarning(formattedMessage);
80+
}
7781
}
7882
}
7983

@@ -87,16 +91,18 @@ public override void ExecuteCmdlet()
8791
string reasonPhrase = null;
8892
string message = null;
8993
string exName = null;
90-
string supressWarningOrErrorValue = System.Environment.GetEnvironmentVariable(BreakingChangeAttributeHelper.SUPPRESS_ERROR_OR_WARNING_MESSAGE_ENV_VARIABLE_NAME);
9194
try
9295
{
93-
bool supressWarningOrError;
94-
Boolean.TryParse(supressWarningOrErrorValue, out supressWarningOrError);
95-
if (!supressWarningOrError)
96-
{
97-
WriteWarningWithTimestamp("The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.");
98-
WriteWarningWithTimestamp("The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.");
99-
}
96+
this.WriteIdentifiedWarning(
97+
cmdletName: "",
98+
topic: "",
99+
message: "*** The namespace for all the model classes will change from Microsoft.Azure.Management.Monitor.Management.Models to Microsoft.Azure.Management.Monitor.Models in future releases.",
100+
withTimeStamp: true);
101+
this.WriteIdentifiedWarning(
102+
cmdletName: "",
103+
topic: "",
104+
message: "*** The namespace for output classes will be uniform for all classes in future releases to make it independent of modifications in the model classes.",
105+
withTimeStamp: true);
100106
this.ProcessRecordInternal();
101107
}
102108
catch (AggregateException ex)

0 commit comments

Comments
 (0)