using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace PowerOff
{
/// <summary>
/// 向D:\LogFiles写数据log
/// </summary>
public partial class 写LOG到TXT文件 : Form
{
public 写LOG到TXT文件()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//创建日志文件夹
if (!Directory.Exists(@"D:\LogFiles"))//如果不存在就创建file文件夹
{
Directory.CreateDirectory(@"D:\LogFiles");
}
//任务开始
WriteLog("\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":执行提醒任务。");
WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":程序完成!");
}
/// <summary>
/// 写日志
/// </summary>
/// <param name="strLogs">日志内容</param>
public void WriteLog(string strLogs)
{
FileStream fs = new FileStream(@"D:\LogFiles\" + DateTime.Now.ToString("yyyyMMdd") + "log.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine(strLogs);
m_streamWriter.Flush();
m_streamWriter.Close();
fs.Close();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace PowerOff
{
/// <summary>
/// 向D:\LogFiles写数据log
/// </summary>
public partial class 写LOG到TXT文件 : Form
{
public 写LOG到TXT文件()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//创建日志文件夹
if (!Directory.Exists(@"D:\LogFiles"))//如果不存在就创建file文件夹
{
Directory.CreateDirectory(@"D:\LogFiles");
}
//任务开始
WriteLog("\r\n" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":执行提醒任务。");
WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":程序完成!");
}
/// <summary>
/// 写日志
/// </summary>
/// <param name="strLogs">日志内容</param>
public void WriteLog(string strLogs)
{
FileStream fs = new FileStream(@"D:\LogFiles\" + DateTime.Now.ToString("yyyyMMdd") + "log.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine(strLogs);
m_streamWriter.Flush();
m_streamWriter.Close();
fs.Close();
}
}
}