当前位置 : 主页 > 编程语言 > c语言 >

如何在不使用第三方库的情况下登录C#?

来源:互联网 收集:自由互联 发布时间:2021-06-25
我想在我的应用程序中实现日志记录,但宁愿不使用任何外部框架,如log4net. 所以我想像DOS的echo这样做一个文件.最有效的方法是什么? 有没有办法记录未使用外部框架记录的未处理的异
我想在我的应用程序中实现日志记录,但宁愿不使用任何外部框架,如log4net.

所以我想像DOS的echo这样做一个文件.最有效的方法是什么?

有没有办法记录未使用外部框架记录的未处理的异常?

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();

}

有关更多信息MSDN:

网友评论