How to show Console.WriteLine output in my browser console or output window?

You can use Debug.Writeline("debug information"). It will be displayed in the Output window.


Console.WriteLine(...) will not be displayed. If you absolutely need to see output in the debugger, you'll have to use

System.Diagnostics.Debug.WriteLine("This will be displayed in output window");

and view it in the Output window. You can open the output window by going to Debug -> Window -> Output:

enter image description here

Here's an example of what this will all look like:

enter image description here

For further readings, check out this SO post.


You can write to your Javascript console from your C# Code using the following class

using System.Web;

public static class Javascript
{
    static string scriptTag = "<script type=\"\" language=\"\">{0}</script>";
    public static void ConsoleLog(string message)
    {       
        string function = "console.log('{0}');";
        string log = string.Format(GenerateCodeFromFunction(function), message);
        HttpContext.Current.Response.Write(log);
    }

    public static void Alert(string message)
    {
        string function = "alert('{0}');";
        string log = string.Format(GenerateCodeFromFunction(function), message);
        HttpContext.Current.Response.Write(log);
    }

    static string GenerateCodeFromFunction(string function)
    {
        return string.Format(scriptTag, function);
    }
}

Works just like its JS version, it actually converts your message to JS and injects it into the page.