如何做好记录在C#? [英] How to do logging in c#?
本文介绍了如何做好记录在C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的应用程序中实现记录,但宁可不使用任何外部框架,如log4net的。
所以,我希望做像该做什么的回声文件。什么是做到这一点的最有效的方法是什么?
有没有一种方法来记录未处理的记录,而无需使用外部框架例外?
解决方案
公共无效记录器(串线)
{
//写入字符串到file.append模式被激活,使日志
//行获得附加的test.txt比擦的内容,写日志
System.IO.StreamWriter文件=新System.IO.StreamWriter(C:\\ test.txt的,真正的);
file.WriteLine(线);
file.Close();
}
有关详细信息, MSDN :
I would like to implement logging in my application but would rather not use any outside frameworks like log4net.
So I would like to do something like Dos's echo to file. What is the most effective way to do it?
Is there a way to log unhandled exceptions logged without using an outside framework?
解决方案
public void Logger(String lines)
{
// Write the string to a file.append mode is enabled so that the log
// lines get appended to test.txt than wiping content and writing the log
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt",true);
file.WriteLine(lines);
file.Close();
}
For more information MSDN:
这篇关于如何做好记录在C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文