当前位置:网站首页>C logging method
C logging method
2022-07-07 10:14:00 【Abacus】
public void WriteLogFile(string input)
{
string logPath = Directory.GetCurrentDirectory() + "\\LogFile";
// Judge whether the folder under this path exists , Create a new folder if it does not exist
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
}
// Specifies the directory for the log files
string fname = logPath + "\\LogFile.txt";
// Define file information objects
FileInfo finfo = new FileInfo(fname);
if (!finfo.Exists)
{
FileStream fs;
fs = File.Create(fname);
fs.Close();
finfo = new FileInfo(fname);
}
// Determine whether the file exists and whether it is greater than 2K
if (finfo.Length > 1024 * 1024 * 10)
{
// The document exceeds 10MB Rename
File.Move(Directory.GetCurrentDirectory() + "\\LogFile.txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\LogFile.txt");
}
// Create a write only file stream
using (FileStream fs = finfo.OpenWrite())
{
// Create a write data stream based on the file stream created above
StreamWriter w = new StreamWriter(fs);
// Set the start position of the write data stream to the end of the file stream
w.BaseStream.Seek(0, SeekOrigin.End);
// write in “Log Entry : ”
w.Write("\n\rLog Entry : ");
// Write the current system time and wrap
w.Write("{0} {1} \n\r", DateTime.Now.ToLongTimeString(),
DateTime.Now.ToLongDateString());
// Write log contents and wrap
w.Write(input + "\n\r");
// write in ------------------------------------“ And line breaks
w.Write("------------------------------------\n\r");
// Empty buffer contents , And write the contents of the buffer to the underlying stream
w.Flush();
// Close the write data stream
w.Close();
}
}
边栏推荐
- MCU is the most popular science (ten thousand words summary, worth collecting)
- Internship log - day07
- Fiddler break point
- Analyze Android event distribution mechanism according to popular interview questions (I)
- Postman interface test III
- UnityWebRequest基础使用之下载文本、图片、AB包
- ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
- ORM--查询类型,关联查询
- Agile course training
- The physical meaning of imaginary number J
猜你喜欢
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
ORM -- query type, association query
LLVM之父Chris Lattner:為什麼我們要重建AI基礎設施軟件
字节跳动 Kitex 在森马电商场景的落地实践
Leetcode exercise - 113 Path sum II
Bean 作⽤域和⽣命周期
ORM--查询类型,关联查询
ArcGIS operation: batch modify attribute table
Postman interface test II
Garbage disposal method based on the separation of smart city and storage and living digital home mode
随机推荐
The physical meaning of imaginary number J
STM32中AHB总线_APB2总线_APB1总线这些是什么
request对象对请求体,请求头参数的解析
Introduction to energy Router: Architecture and functions for energy Internet
Fiddler break point
企业实战|复杂业务关系下的银行业运维指标体系建设
Bit operation ==c language 2
Guys, have you ever encountered the case of losing data when Flink CDC reads mysqlbinlog? Every time the task restarts, there is a probability of losing data
phpcms实现PC网站接入微信Native支付
Win10 installation vs2015
CONDA creates virtual environment offline
Integer inversion
C socke server, client, UDP
ES6中的函數進階學習
ES6中的函数进阶学习
Postman interface test VII
Mongodb creates an implicit database as an exercise
Postman interface test IV
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
Using keras in tensorflow to build convolutional neural network