Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
105 changes: 68 additions & 37 deletions src/System.Management.Automation/utils/StructuredTraceSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ internal void TraceGlobalAppDomainHeader()
OutputLine(
PSTraceSourceOptions.All,
"\tCurrent time: {0}",
DateTime.Now);
DateTime.Now.ToString());

// OS build

Expand Down Expand Up @@ -429,7 +429,7 @@ internal void TracerObjectHeader(
OutputLine(
PSTraceSourceOptions.All,
"\tAssembly File Timestamp: {0}",
assemblyFileInfo.CreationTime);
assemblyFileInfo.CreationTime.ToString());
}

StringBuilder flagBuilder = new StringBuilder();
Expand Down Expand Up @@ -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());
}

/// <summary>
/// Traces the formatted output when PSTraceSourceOptions.WriteLine is enabled.
/// </summary>
Expand Down Expand Up @@ -1046,10 +1096,10 @@ internal void WriteLine(object arg)
/// </param>
/// <param name="classFormatter">
/// This is the trace class formatter. For instance,
/// TraceError has a formatter like "ERROR: {0}"
/// TraceError has a formatter like "ERROR: {0}".
/// </param>
/// <param name="format">
/// Additional format string
/// Additional format string.
/// </param>
/// <param name="args">
/// Arguments for the additional format string
Expand All @@ -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)
Expand All @@ -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.
Expand All @@ -1108,10 +1156,10 @@ private void FormatOutputLine(
/// GetCallingMethodNameAndParameters.
/// </remarks>
/// <param name="skipFrames">
/// The number of frames to skip in the calling stack
/// The number of frames to skip in the calling stack.
/// </param>
/// <returns>
/// The name of the method on the stack
/// The name of the method on the stack.
/// </returns>
private static string GetCallingMethodNameAndParameters(int skipFrames)
{
Expand Down Expand Up @@ -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;
/// <summary>
/// Composes a line of trace output and then writes it.
/// </summary>
/// <param name="flag">
/// The flag that caused the line to be traced
/// The flag that caused the line to be traced.
/// </param>
/// <param name="format">
/// The string to write with format symbols if necessary
/// The string to write with format symbols if necessary.
/// </param>
/// <param name="args">
/// Arguments to the format string
/// <param name="arg">
/// Arguments to the format string.
/// </param>
/// <remarks>
/// The line is composed by prefixing the process name, thread ID,
Expand All @@ -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.
Expand All @@ -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
{
Expand Down