-
自定义Log 写到文件中
- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.IO;
- using System.Text;
-
- public class NetLog
- {
-
-
-
-
-
-
- public static void WriteTextLog(string action, string strMessage, DateTime time)
- {
- string path = AppDomain.CurrentDomain.BaseDirectory + @"SystemLog";
- if (!Directory.Exists(path))
- Directory.CreateDirectory(path);
-
- string fileFullPath = path + time.ToString("yyyy-MM-dd") + ".System.txt";
- StringBuilder str = new StringBuilder();
- str.Append("Time: " + time.ToString() + "
");
- str.Append("Action: " + action + "
");
- str.Append("Message: " + strMessage + "
");
- str.Append("-----------------------------------------------------------
");
- StreamWriter sw;
- if (!File.Exists(fileFullPath))
- {
- sw = File.CreateText(fileFullPath);
- }
- else
- {
- sw = File.AppendText(fileFullPath);
- }
- sw.WriteLine(str.ToString());
- sw.Close();
- }
- }
-
相关阅读:
第二阶段冲刺6
第二阶段冲刺5
第二阶段冲刺4
第二阶段冲刺3
暑假学习进度七
暑假学习进度六
暑假学习进度五
暑假学习进度四
暑假学习进度三
暑假学习进度二
-
原文地址:https://www.cnblogs.com/TddCoding/p/8831581.html
Copyright © 2020-2023
润新知