如何创建和写入日志文件 [英] How to create and write into log file

查看:70
本文介绍了如何创建和写入日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在winforms的日志文件中创建和写入信息,错误和警告。

尝试了下面的代码,但我仍然无法记录错误。



我尝试过:



I need to create and write the information, error and warning into the log file in winforms.
Have tried the below code but still i am not able to log the errors.

What I have tried:

Trace.TraceInformation("Your Information");
                Trace.TraceError("Your Error");
                Trace.TraceWarning("Your Warning");

推荐答案

要利用.NET框架的跟踪功能,首先必须设置跟踪侦听器 - 跟踪消息将到达的实际存储...

在您的代码中只有消息,但无处可看到一个人收听这些消息...

在MSDN上查看简单但完整的样本...

跟踪类(System.Diagnostics) [ ^ ]
To utilize Trace capabilities of the .NET framework, you first have to set up a trace listener - an actual storage to where the trace messages will go...
In you code there is only messages, but nowhere to see one who listens to those messages...
Se the simple, but complete sample at MSDN...
Trace Class (System.Diagnostics)[^]


您需要设置跟踪侦听器 [ ^ ]确定输出的去向。如果没有它,您的输出将转到默认侦听器,即调试窗口。事件日志,日志文件,控制台等有许多类型的监听器 ...从链接读取,我相信你会能从那里拿走。
You need to set up a Trace Listener[^] to determine where you want the output to go. Without that, your output just goes to the default listener, which is the debug window. There are many types of Listener for the Event Log, a Log File, the Console, etc... have a read from the link, and I'm sure you'll be able to take it from there.


这篇关于如何创建和写入日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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