c#快速写本地日志方法

1、引用

1
2
3
using System;
using System.IO;
using System.Text;

2、具体方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void Writelog(string msg)
  {
   StreamWriter stream;
   //写入日志内容
   string path = AppDomain.CurrentDomain.BaseDirectory;
   //检查上传的物理路径是否存在,不存在则创建
   if (!Directory.Exists(path))
   {
    Directory.CreateDirectory(path);
   }
   stream = new StreamWriter(path + "\\log.txt", true, Encoding.Default);
   stream.Write(DateTime.Now.ToString() + ":" + msg);
   stream.Write("\r\n");
   stream.Flush();
   stream.Close();
  }
posted @ 2019-05-21 15:13  京不里京京  阅读(921)  评论(0编辑  收藏  举报