如何捕获从服务的C#控制台输出? [英] How to capture console output from a service C#?

查看:179
本文介绍了如何捕获从服务的C#控制台输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经部署到远程客户系统中的C#的服务。该应用程序写入的诊断的大量信息到控制台(即Console.WriteLine())。该服务是不是做什么它应该。我们如何能捕捉从另一个应用程序的服务控制台输出?

We have a C# service that is deployed to a remote customer system. The application writes a substantial amount of "diagnostic" information to the console (i.e. Console.WriteLine()). The service isn't "doing what it should." How can we capture the console output from the service in another application?

一个WinForm的版本的应用程序可以在客户所在地进行加载。它,不幸的是,正常工作

A WinForm version the application can be loaded at the customer location. It, unfortunately, functions correctly.

更新:

我们能够改改服务,但不希望让在这个时候发生重大变化。

We are able to change the change the service, but would prefer not to make major changes at this time.

我们也记录到MSMQ,但仅限于重要的事件。该服务确实与互动MSMQ其正常运作。或者,至少,它应该。该服务似乎并没有从MSMQ拉动项目时,WinForm的版本一样。所以,编写打算控制台消息可能有问题。

We are also logging to MSMQ, but only for "important" events. This service does interact with MSMQ for its normal operations. Or, at least, it should. The service doesn't seem to be pulling items from MSMQ when the WinForm version does. So, writing the messages that are going to the console could be problematic.

推荐答案

您可以更改服务代码的所有的?如果是这样,使用Console.SetOut写入到一个文件中,而不是将呼叫的最明显的第一端口。然后换用适当的日志库下一个版本:)

Are you able to change the service code at all? If so, using Console.SetOut to write to a file instead would be the most obvious first port of call. Then change to using a proper logging library for the next release :)

这篇关于如何捕获从服务的C#控制台输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆