如何在不使用 3rd 方库的情况下登录 C#? [英] How do I do logging in C# without using 3rd party libraries?
本文介绍了如何在不使用 3rd 方库的情况下登录 C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的应用程序中实现日志记录,但不想使用任何外部框架,如 log4net.
I would like to implement logging in my application, but would rather not use any outside frameworks like log4net.
所以我想对文件做一些类似于 DOS 的 echo 的操作.最有效的方法是什么?
So I would like to do something like DOS's echo to a 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
using(System.IO.StreamWriter file = new System.IO.StreamWriter("c:\test.txt", true))
{
file.WriteLine(lines);
}
}
有关详细信息 MSDN
这篇关于如何在不使用 3rd 方库的情况下登录 C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文