直接调用即可,默认程序
需引用如下两条
using System.IO;
using System.Text;
public static void WriteLogs(int macid, string v)
{
string path = AppDomain.CurrentDomain.BaseDirectory;
string content = macid + v;
if (!string.IsNullOrEmpty(path))
{
path = AppDomain.CurrentDomain.BaseDirectory +"NetLogs";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = path + "\\" + DateTime.Now.ToString("yyyy-MM-dd");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = path + "\\" + DateTime.Now.ToString("yyyy-MM-dd ") + "_" + DateTime.Now.ToString("HH") + ".txt";
if (!File.Exists(path))
{
FileStream fs = File.Create(path);
fs.Close();
}
if (File.Exists(path))
{
StreamWriter sw = new StreamWriter(path, true, Encoding.Default);
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "-->" + content);
// sw.WriteLine("----------------------------------------");
sw.Close();
}
}
}
学习了