使用 System.Diagnostics 进行简单的调试和日志记录 [英] Simple Debug and Logging using System.Diagnostics

查看:41
本文介绍了使用 System.Diagnostics 进行简单的调试和日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将条目写入控制台应用程序,该应用程序将描述操作何时完成,可能会在某一时刻将它们写入 .txt 文件.

I wish to be able to write entries to a console application which will describe when actions have been completed, possibly writing them to a .txt file at one point.

我希望它与同时运行的单独 GUI 应用程序一起使用,以便我可以同时使用该应用程序并监控日志.

I would like it to be used with a separate GUI application running at the same time so i can use the application and monitor the log simultaneously.

我只假设诊断类是正确的工具,但我以前从未使用过任何日志记录方法,所以我欢迎任何其他建议.

I only assume the Diagnostic class is the right tool to use however I have never used any logging methods before, so i welcome any other suggestions.

谢谢

推荐答案

查看 System.Diagnostics.Trace.您可以向其中添加不同的 TraceListener,包括控制台或文件的侦听器.然后用 Trace.Write()/Trace.WriteLine() 替换你所有的 Console.Write()/Console.WriteLine() 调用,你很好.您甚至可以实现自己的 TraceListener(非常简单)将消息发送到您的 GUI 应用.

Look at System.Diagnostics.Trace. You can add different TraceListeners to it, including listeners for the Console or files. Then replace all your Console.Write()/Console.WriteLine() calls with Trace.Write()/Trace.WriteLine() and you're good. You can even implement your own TraceListener (it's very easy) to send the messages to your GUI app.

这篇关于使用 System.Diagnostics 进行简单的调试和日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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