当前位置:网站首页>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();
}
}边栏推荐
- Please ask me a question. I started a synchronization task with SQL client. From Mysql to ADB, the historical data has been synchronized normally
- ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
- The story of Plato and his three disciples: how to find happiness? How to find the ideal partner?
- Differences between MCU and MPU
- Why are social portals rarely provided in real estate o2o applications?
- 【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)
- conda离线创建虚拟环境
- Arcgis操作: 批量修改属性表
- Interface test
- Analyze Android event distribution mechanism according to popular interview questions (II) -- event conflict analysis and handling
猜你喜欢

Arcgis操作: 批量修改属性表

LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件

Weekly recommended short videos: what are the functions of L2 that we often use in daily life?

字节跳动 Kitex 在森马电商场景的落地实践

Web3.0 series distributed storage IPFs

STM32 Basics - memory mapping
![[original] what is the core of programmer team management?](/img/11/d4b9929e8aadcaee019f656cb3b9fb.png)
[original] what is the core of programmer team management?

LLVM之父Chris Lattner:為什麼我們要重建AI基礎設施軟件

Postman interface test I

ArcGIS operation: converting DWG data to SHP data
随机推荐
SolidWorks工程图中添加中心线和中心符号线的办法
虚数j的物理意义
Postman interface test VII
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
ES6中的函数进阶学习
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
Enterprise practice | construction of banking operation and maintenance index system under complex business relations
Win10 installation vs2015
视频化全链路智能上云?一文详解什么是阿里云视频云「智能媒体生产」
Analyze Android event distribution mechanism according to popular interview questions (I)
为什么安装mysql时starting service报错?(操作系统-windows)
ISP、IAP、ICP、JTAG、SWD的编程特点
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
【acwing】786. 第k个数
Integer inversion
官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
ISP、IAP、ICP、JTAG、SWD的编程特点
LeetCode 练习——113. 路径总和 II
ES类和对象、原型
CONDA creates virtual environment offline