I am running an MVC Web application built by using Visual Studio 2017. I want to test some parts of C# code without using debugger breakpoints
. Is there any way to know a certain part of code has run by adding some code at that point? Something like console.log
in Javascript? As to make things more specific I'd like to add this "watcher code" inside the following method:
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
Is the above doable and how?
warn() Probably the most obvious direct replacement for log() , you can just use console. warn() in exactly the same way. The only real difference is the output is a bit yellow.
console. log() is a function used to print information to the console. return on the other hand is a call to pass some value back up to where the call was made.
The console. log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Syntax: console.
console. log specifically is a method for developers to write code to inconspicuously inform the developers what the code is doing. It can be used to alert you that there's an issue, but shouldn't take the place of an interactive debugger when it comes time to debug the code.
Trace.WriteLine
will do (and probably more methods from the Trace
class).
You can use a program called DebugView to real-time monitor the trace generated, or write to a log file using you web.config
file.
Try using System.Diagnostics.Debug.WriteLine("This is a log");
and in Visual Studio open View
and then in Output
you will see the log when running your application.
Console.WriteLine
will do it provided that you have a console to view it in (for a forms application this works when debugging in something like visual studio, but the end user will never see the output)
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