当前位置:网站首页>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();
}
}
边栏推荐
- Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
- Do you have a boss to help look at this error report and what troubleshooting ideas are there? Oracle CDC 2.2.1 flick 1.14.4
- ES6中的函數進階學習
- Embedded background - chip
- Phpcms realizes PC website access to wechat native payment
- 对存储过程进行加密和解密(SQL 2008/SQL 2012)
- Postman interface test I
- STM32中AHB总线_APB2总线_APB1总线这些是什么
- The landing practice of ByteDance kitex in SEMA e-commerce scene
- Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
猜你喜欢
Weekly recommended short videos: what are the functions of L2 that we often use in daily life?
STM32中AHB总线_APB2总线_APB1总线这些是什么
ArcGIS operation: batch modify attribute table
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
[original] what is the core of programmer team management?
VS Code指定扩展安装位置
LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
ORM model -- creation and query of data records
柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?
随机推荐
Differences between MCU and MPU
Phpcms realizes PC website access to wechat native payment
【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)
.NET配置系统
运用tensorflow中的keras搭建卷积神经网络
ORM模型--数据记录的创建操作,查询操作
Guid主键
phpcms实现PC网站接入微信Native支付
Agile course training
Before joining the chain home, I made a competitive product analysis for myself
Advanced function learning in ES6
SolidWorks工程图中添加中心线和中心符号线的办法
嵌入式背景知识-芯片
Enterprise practice | construction of banking operation and maintenance index system under complex business relations
ORM model -- associated fields, abstract model classes
Win10安装VS2015
LeetCode 练习——113. 路径总和 II
Memory ==c language 1
CONDA creates virtual environment offline
每周推荐短视频:L2级有哪些我们日常中经常会用到的功能?