Due to testing and time measuring I have to write some kind of log into an existing C# Winforms project.
I want to minimize change to the application, so I'm limiting my question to replacing text by counting numbers:
I want to pass a line:
Log.WriteLine(position)
many times in the code and then replace "position" with numbers starting from 1 to n in turn.
I can't use a counter in this case because of many loops I don´t get the right position.
Take a look at this.
You could retrieve the file name and line number instead of a counter.
static private void Trace()
{
StackFrame callStack = new StackFrame(1, true);
Log.WriteLine(
String.Format("At {0}:{1}",
callStack.GetFileName(),
callStack.GetFileLineNumber()));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With