我可以写入控制台日志以使用 C# 调试 Web 应用程序吗

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12947093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:02:42  来源:igfitidea点击:

Can I write to the console log to debug a web application with C#

c#

提问by

I would like to log some variables in my ASP MVC3 application while I debug. I tried some different things such as:

我想在调试时在我的 ASP MVC3 应用程序中记录一些变量。我尝试了一些不同的事情,例如:

Debug.Log(topTitle + " " + subTitle);

This doesn't seem to work. How can I write to the console of VS2010 from my C# code?

这似乎不起作用。如何从我的 C# 代码写入 VS2010 的控制台?

采纳答案by Habib

To write to Console Window in Visual studio use:

要在 Visual Studio 中写入控制台窗口,请使用:

System.Diagnostics.Debug.WriteLine(topTitle + " " + subTitle);

Below is the screenshot of its working:

下面是它的工作截图:

enter image description here

在此处输入图片说明

回答by Damir Arh

You can use Debugclass to emit debugging information from you application. You can even add trace listenerto your web.configfile to redirect the output to a file or event log when you're not debugging from Visual Studio.

您可以使用Debug类从您的应用程序发出调试信息。当您不从 Visual Studio 调试时,您甚至可以将跟踪侦听器添加到您的web.config文件以将输出重定向到文件或事件日志。

回答by Ravi Gadag

To write to Console Window in Visual studio use:

要在 Visual Studio 中写入控制台窗口,请使用:

System.Diagnostics.Debug.WriteLine(topTitle + " " + subTitle);

or you can view and manipulate with Immediate window. Immediate window

或者您可以查看和操作Immediate window直接窗口

回答by Jomy John

System.Diagnostics.Debugdoes not have log method. You can use System.Diagnostics.Debug.WriteLine. You can view output in output window . Then make sure that you are running under debug mode.

System.Diagnostics.Debug没有日志方法。您可以使用System.Diagnostics.Debug.WriteLine. 您可以在输出窗口中查看输出。然后确保您在调试模式下运行。

. Debug information is only visible when you are running in Debug mode. In Release mode Debug statements will not visible (you can use Trace instead of Debug if you want these statements to be visible in Release mode).

. 调试信息仅在您在调试模式下运行时可见。在 Release 模式下,Debug 语句将不可见(如果您希望这些语句在 Release 模式下可见,则可以使用 Trace 而不是 Debug)。

Please refer the following article

请参考以下文章

How to trace and debug in Visual C#

如何在 Visual C# 中进行跟踪和调试