By definition, the stack trace is an output of the active stack frames at the current execution point in a program, generally accessed via an Exception.
@David Yaw gave you the correct way to add additional information to a stack trace, as it bubbles up the exception stack. To rephrase, you should only be adding your custom data to the stack trace, when it is the result of an exception.
Either create some centrally accessible List collection to store logging data in, or use proper try/catch with exception bubbling as David recommended.
for example.
try
{
doSomethingThatMightFailAndThrowAnException();
}
catch (Exception ex)
{
throw new Exception("Here is some custom data to add to the trace...",ex);
// Notice adding the ex as the second parameter preserves the original exception trace
}
throw new InvalidOperationException("argument1:" + test + ", argument2:" + test2);