ASP.NET 中的 Console.WriteLine 在哪里?

编程入门 行业动态 更新时间:2024-10-21 18:56:00
本文介绍了ASP.NET 中的 Console.WriteLine 在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 J2EE 应用程序中(例如在 WebSphere 中运行的应用程序),当我使用 System.out.println() 时,我的文本变为标准输出,由 WebSphere 管理员映射到文件控制台.

In a J2EE application (like one running in WebSphere), when I use System.out.println(), my text goes to standard out, which is mapped to a file by the WebSphere admin console.

在 ASP.NET 应用程序中(例如在 IIS 中运行的应用程序),Console.WriteLine() 的输出到哪里去了?IIS 进程必须有 stdin、stdout 和 stderr;但是标准输出是映射到 Windows 版本的/dev/null 还是我在这里遗漏了一个关键概念?

In an ASP.NET application (like one running in IIS), where does the output of Console.WriteLine() go? The IIS process must have a stdin, stdout and stderr; but is stdout mapped to the Windows version of /dev/null or am I missing a key concept here?

我不问是否应该在那里登录(我使用 log4net),但是输出到哪里去了?我最好的信息来自这个讨论,他们说Console.SetOut() 可以改变TextWriter,但是还是没有回答Console的初始值是什么,或者如何在config/中设置的问题运行时代码之外.

I'm not asking if I should log there (I use log4net), but where does the output go? My best info came from this discussion where they say Console.SetOut() can change the TextWriter, but it still didn't answer the question on what the initial value of the Console is, or how to set it in config/outside of runtime code.

推荐答案

如果您查看 Console 类.NET_Reflector" rel="noreferrer">.NET Reflector,你会发现如果一个进程没有关联的控制台,Console.Out 和 Console.Error 由 Stream.Null(包裹在 TextWriter 中)支持,它是 Stream 的虚拟实现,基本上忽略所有输入,并且没有输出.

If you look at the Console class in .NET Reflector, you'll find that if a process doesn't have an associated console, Console.Out and Console.Error are backed by Stream.Null (wrapped inside a TextWriter), which is a dummy implementation of Stream that basically ignores all input, and gives no output.

所以它在概念上等同于 /dev/null,但实现更加精简:没有实际 I/O 发生在空设备上.

So it is conceptually equivalent to /dev/null, but the implementation is more streamlined: there's no actual I/O taking place with the null device.

另外,除了调用SetOut,没有办法设置默认值.

Also, apart from calling SetOut, there is no way to configure the default.

更新 2020-11-02:由于这个答案在 2020 年仍在收集选票,可能应该注意的是,在 ASP.NET Core 下,通常附有控制台.您可以配置 ASP.NET Core IIS模块通过 stdoutLogEnabled 和 stdoutLogFile 设置将所有 stdout 和 stderr 输出重定向到日志文件:

Update 2020-11-02: As this answer is still gathering votes in 2020, it should probably be noted that under ASP.NET Core, there usually is a console attached. You can configure the ASP.NET Core IIS Module to redirect all stdout and stderr output to a log file via the stdoutLogEnabled and stdoutLogFile settings:

<system.webServer> <aspNetCore processPath="dotnet" arguments=".MyApp.dll" hostingModel="inprocess" stdoutLogEnabled="true" stdoutLogFile=".logsstdout" /> <system.webServer>

更多推荐

ASP.NET 中的 Console.WriteLine 在哪里?

本文发布于:2023-11-14 10:06:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586923.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   ASP   WriteLine   Console

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!