diff --git a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs
index 7e4c4f3b6dd..4545083afbb 100644
--- a/src/System.Management.Automation/engine/CmdletParameterBinderController.cs
+++ b/src/System.Management.Automation/engine/CmdletParameterBinderController.cs
@@ -980,7 +980,7 @@ private void VerifyParameterSetSelected()
{
ParameterBinderBase.bindingTracer.WriteLine(
"{0} valid parameter sets, using the DEFAULT PARAMETER SET: [{0}]",
- this.BindableParameters.ParameterSetCount,
+ this.BindableParameters.ParameterSetCount.ToString(),
_commandMetadata.DefaultParameterSetName);
_currentParameterSetFlag =
diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs
index 0edc38331bb..46ac2063192 100644
--- a/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs
+++ b/src/System.Management.Automation/engine/remoting/fanin/WSManTransportManager.cs
@@ -1878,7 +1878,7 @@ private static void OnCreateSessionCallback(IntPtr operationContext,
if (errorStruct.errorCode != 0)
{
- tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode, errorStruct.errorDetail);
+ tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode.ToString(), errorStruct.errorDetail);
// Test error code for possible session connection retry.
if (sessionTM.RetrySessionCreation(errorStruct.errorCode))
@@ -1975,7 +1975,7 @@ private static void OnCloseSessionCompleted(IntPtr operationContext,
if (errorStruct.errorCode != 0)
{
- tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode, errorStruct.errorDetail);
+ tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode.ToString(), errorStruct.errorDetail);
TransportErrorOccuredEventArgs eventargs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(
sessionTM.WSManAPIData.WSManAPIHandle,
@@ -2027,7 +2027,7 @@ private static void OnRemoteSessionDisconnectCompleted(IntPtr operationContext,
if (errorStruct.errorCode != 0)
{
- tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode, errorStruct.errorDetail);
+ tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode.ToString(), errorStruct.errorDetail);
TransportErrorOccuredEventArgs eventargs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(
sessionTM.WSManAPIData.WSManAPIHandle,
@@ -2095,7 +2095,7 @@ private static void OnRemoteSessionReconnectCompleted(IntPtr operationContext,
if (errorStruct.errorCode != 0)
{
- tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode, errorStruct.errorDetail);
+ tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode.ToString(), errorStruct.errorDetail);
TransportErrorOccuredEventArgs eventargs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(
sessionTM.WSManAPIData.WSManAPIHandle,
@@ -2198,7 +2198,7 @@ private static void OnRemoteSessionConnectCallback(IntPtr operationContext,
if (errorStruct.errorCode != 0)
{
- tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode, errorStruct.errorDetail);
+ tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode.ToString(), errorStruct.errorDetail);
TransportErrorOccuredEventArgs eventargs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(
sessionTM.WSManAPIData.WSManAPIHandle,
@@ -2304,7 +2304,7 @@ private static void OnRemoteSessionSendCompleted(IntPtr operationContext,
// way of notifying the same using state change events.
if ((errorStruct.errorCode != 0) && (errorStruct.errorCode != 995))
{
- tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode, errorStruct.errorDetail);
+ tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode.ToString(), errorStruct.errorDetail);
TransportErrorOccuredEventArgs eventargs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(
sessionTM.WSManAPIData.WSManAPIHandle,
@@ -2371,7 +2371,7 @@ private static void OnRemoteSessionDataReceived(IntPtr operationContext,
if (errorStruct.errorCode != 0)
{
- tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode, errorStruct.errorDetail);
+ tracer.WriteLine("Got error with error code {0}. Message {1}", errorStruct.errorCode.ToString(), errorStruct.errorDetail);
TransportErrorOccuredEventArgs eventargs = WSManTransportManagerUtils.ConstructTransportErrorEventArgs(
sessionTM.WSManAPIData.WSManAPIHandle,
diff --git a/src/System.Management.Automation/namespaces/LocationGlobber.cs b/src/System.Management.Automation/namespaces/LocationGlobber.cs
index 4ed25f69b28..ed8290ef1ec 100644
--- a/src/System.Management.Automation/namespaces/LocationGlobber.cs
+++ b/src/System.Management.Automation/namespaces/LocationGlobber.cs
@@ -4402,7 +4402,7 @@ private static bool IsChildNameAMatch(
}
} while (false);
- s_tracer.WriteLine("result = {0}; childName = {1}", result, childName);
+ s_tracer.WriteLine("result = {0}; childName = {1}", result.ToString(), childName);
return result;
}
diff --git a/src/System.Management.Automation/utils/StructuredTraceSource.cs b/src/System.Management.Automation/utils/StructuredTraceSource.cs
index 8fa7ee771a5..c3d7b566205 100644
--- a/src/System.Management.Automation/utils/StructuredTraceSource.cs
+++ b/src/System.Management.Automation/utils/StructuredTraceSource.cs
@@ -346,7 +346,7 @@ internal void TraceGlobalAppDomainHeader()
OutputLine(
PSTraceSourceOptions.All,
"\tCurrent time: {0}",
- DateTime.Now);
+ DateTime.Now.ToString());
// OS build
@@ -429,7 +429,7 @@ internal void TracerObjectHeader(
OutputLine(
PSTraceSourceOptions.All,
"\tAssembly File Timestamp: {0}",
- assemblyFileInfo.CreationTime);
+ assemblyFileInfo.CreationTime.ToString());
}
StringBuilder flagBuilder = new StringBuilder();
@@ -924,6 +924,56 @@ internal void WriteLine(string format, object arg1)
}
}
+ internal void WriteLine(string format, bool arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
+ internal void WriteLine(string format, byte arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
+ internal void WriteLine(string format, char arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
+ internal void WriteLine(string format, decimal arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
+ internal void WriteLine(string format, double arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
+ internal void WriteLine(string format, float arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
+ internal void WriteLine(string format, int arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
+ internal void WriteLine(string format, long arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
+ internal void WriteLine(string format, uint arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
+ internal void WriteLine(string format, ulong arg1)
+ {
+ WriteLine(format, (object)arg1.ToString());
+ }
+
///
/// Traces the formatted output when PSTraceSourceOptions.WriteLine is enabled.
///
@@ -1046,10 +1096,10 @@ internal void WriteLine(object arg)
///
///
/// This is the trace class formatter. For instance,
- /// TraceError has a formatter like "ERROR: {0}"
+ /// TraceError has a formatter like "ERROR: {0}".
///
///
- /// Additional format string
+ /// Additional format string.
///
///
/// Arguments for the additional format string
@@ -1064,7 +1114,6 @@ private void FormatOutputLine(
{
// First format the class format string and the
// user provided format string together
-
StringBuilder output = new StringBuilder();
if (classFormatter != null)
@@ -1081,13 +1130,12 @@ private void FormatOutputLine(
}
// finally trace the output
-
OutputLine(flag, output.ToString());
}
catch
{
// Eat all exceptions
-
+ //
// Do not assert here because exceptions can be
// raised while a thread is shutting down during
// normal operation.
@@ -1108,10 +1156,10 @@ private void FormatOutputLine(
/// GetCallingMethodNameAndParameters.
///
///
- /// The number of frames to skip in the calling stack
+ /// The number of frames to skip in the calling stack.
///
///
- /// The name of the method on the stack
+ /// The name of the method on the stack.
///
private static string GetCallingMethodNameAndParameters(int skipFrames)
{
@@ -1251,38 +1299,31 @@ private static StringBuilder GetLinePrefix(PSTraceSourceOptions flag)
return prefixBuilder;
}
- private static void AddTab(ref StringBuilder lineBuilder)
+ private static void AddTab(StringBuilder lineBuilder)
{
// The Trace.IndentSize does not change at all
// through the running of the process so there
// are no thread issues here.
-
int indentSize = Trace.IndentSize;
-
int threadIndentLevel = ThreadIndentLevel;
- for (
- int index = 0;
- index < indentSize * threadIndentLevel;
- index++)
- {
- lineBuilder.Append(" ");
- }
+ lineBuilder.Append(System.Management.Automation.Internal.StringUtil.Padding(indentSize * threadIndentLevel));
}
// used to find and blocks cyclic-loops in tracing.
+
private bool _alreadyTracing = false;
///
/// Composes a line of trace output and then writes it.
///
///
- /// The flag that caused the line to be traced
+ /// The flag that caused the line to be traced.
///
///
- /// The string to write with format symbols if necessary
+ /// The string to write with format symbols if necessary.
///
- ///
- /// Arguments to the format string
+ ///
+ /// Arguments to the format string.
///
///
/// The line is composed by prefixing the process name, thread ID,
@@ -1293,7 +1334,7 @@ private static void AddTab(ref StringBuilder lineBuilder)
internal void OutputLine(
PSTraceSourceOptions flag,
string format,
- params object[] args)
+ string arg = null)
{
// if already tracing something for this current TraceSource,
// dont trace again. This will block cyclic-loops from happening.
@@ -1315,28 +1356,18 @@ internal void OutputLine(
{
// Get the line prefix string which includes things
// like App name, clock tick, thread ID, etc.
-
lineBuilder.Append(GetLinePrefix(flag));
}
// Add the spaces for the indent
+ AddTab(lineBuilder);
- AddTab(ref lineBuilder);
-
- if (args != null && args.Length > 0)
+ if (arg != null)
{
- for (int index = 0; index < args.Length; ++index)
- {
- if (args[index] == null)
- {
- args[index] = "null";
- }
- }
-
lineBuilder.AppendFormat(
CultureInfo.CurrentCulture,
format,
- args);
+ arg);
}
else
{