运维开发网

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

运维开发网 https://www.qedev.com 2020-05-29 10:09 出处:网络 作者:运维开发网整理
我想在我的应用程序中实现日志记录,但宁愿不使用任何外部框架,如log4net. 所以我想像DOS的echo这样做一个文件.最有效的方法是什么? 有没有办法记录未使用外部框架记录的未处理的异常? public void Logger(String lines) { // Write the string to a file.append mode is enabled so that the l
我想在我的应用程序中实现日志记录,但宁愿不使用任何外部框架,如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:

0

精彩评论

暂无评论...
验证码 换一张
取 消