Vic*_*ues 24 c# asp.net console
我想在请求处理期间打印一些跟踪.
但是当我在这个环境中创建Console.WriteLine("something")时,没有显示任何内容.
缺少什么,为了使用控制台打印这些痕迹我需要做什么?
小智 9
除了已经提到的方法之外,您只需写入日志文件:
File.AppendAllText(@"c:\log.txt", @"Debug Message Here!" + Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)
当然,您可以使用Server.MapPath在Web目录中编写该文件.
我知道这已经很晚了,但您可以使用以下类从C#脚本写入Javascript控制台
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);
}
}
Run Code Online (Sandbox Code Playgroud)
这样,您可以在点击网站时实时查看日志消息,就像在js中一样.