Reputation: 1780
I have an ASP.NET Core application and I do not know what to do next. Note - I use Visual Studio 2019.
I have a progress for a image download. I would like to know if my code works well and outputs the correct value (if you notice something or if there is a better solution you are welcome to inform me). But I don't want to constantly debug all the steps through the code (which would take a lot of time at this point).
So my idea was to keep the progress
somewhere (maybe in a console log), so I can watch it all the time.
What did I try?
I've added a simple Console.WriteLine (progress)
into my method, but I see no console. Then I tried it with the Command Window
and >? progress
, but it only outputs the value if the breakpoint is set,
which leads to the same problem again.
What would I have to adjust so I can see the progress in a log?
Here is my code:
while(...)
{
if (ExpectedStreamSize.HasValue && _configSize.HasValue)
{
var expected = ExpectedStreamSize + _configSize.Value;
var progress = _stream.ReadPosition / (float) expected;
var limitedProgress = progress > 1 ? 1 : progress;
var epsilon = 0.001;
if (!_lastReportedProgress.HasValue || _lastReportedProgress.Value + epsilon < limitedProgress)
_onProgressChanged?.Invoke(limitedProgress);
_lastReportedProgress = limitedProgress;
Console.WriteLine(progress); // I setted my breakpoint in here
}
}
Upvotes: 1
Views: 101
Reputation: 1614
You could try logging to file. This way you can debug even in release mode or when running the executable outside of Visual Studio.
public void LogToFile(string text)
{
string path = @"c:\temp\MyTest.txt";
string appendText = text + Environment.NewLine;
File.AppendAllText(path, appendText);
}
Upvotes: 1
Reputation:
While debugging, right click on the variable, choose "add watch". You will see it's value bellow in the watches window.
Upvotes: 0