Is there a console log for asp.net?

2020-05-25 23:51发布

问题:

If I have IF statement like below:

If currentdate >= rating1  then
    status = 2
ELSEIF currentdate >= rating2  then
    daylight_savings_status = 0
ELSEIF currentdate >= rating3  then
    daylight_savings_status = 1
ELSE 
    daylight_savings_status = 1
End If

Is there something like in javascript

console.log('test');

that I can test on the which IF statement is truth of the statement?

This way I be able to test it on the firebug(firefox).

回答1:

For Server Side

C# & VB.Net Server Side - This will show in the Visual Studio Output window.

System.Diagnostics.Debug.WriteLine(log data here)

Client Side JavaScript/Jquery - This will show in the browser devtools console window. Works on all popular browsers.

console.log(log data here) 


回答2:

I would try to output it to the clients console ONLY If the Console.WriteLine() function doesnt work for you.

Page.Response.Write("<script>console.log('" + msg + "');</script>");

Ultimately though you should try to write debug statements in your own console (with System.Diagnostics.Debug.WriteLine(...)) and not the client's.

NB System.Diagnostics.Debug.WriteLine(...); gets it into the Immediate Window in Visual Studio 2008.

Go to menu Debug -> Windows -> Immediate:



回答3:

This may be a moot point, but I wanted to make a note on this. As @snowYetis answer tells you the correct way to write to the system console for debugging puposes. My "trick" to making this a little more bearable during development is making a helper class somewhere in your project for you to import and use. One of the helper methods I ALWAYS implement in my projects is this one:

public void DebugLog(String msg)
{
    System.Diagnostics.Debug.WriteLine(msg);
}

This way you only need to call your Helper.DebugLog(e.Message); when you want to log to console without having to dot your way into madness :)

Hope this helps someone



回答4:

For outputting to your server console, use :

Console.WriteLine("test");


标签: asp.net