ab56a9bcf7
SVN-Revision: r240
75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace SynchronousOven
|
|
{
|
|
public static class LogUtil
|
|
{
|
|
|
|
/// <summary>
|
|
/// Log文件夹目录
|
|
/// </summary>
|
|
static string folderPath;
|
|
/// <summary>
|
|
/// 日志文件目录
|
|
/// </summary>
|
|
static string filePath;
|
|
|
|
/// <summary>
|
|
/// 写入日志
|
|
/// </summary>
|
|
public static void WriteLocalLog(string log)
|
|
{
|
|
try
|
|
{
|
|
//获取程序目录,并完整日志文件夹目录
|
|
folderPath = System.IO.Directory.GetCurrentDirectory() + "\\Log";
|
|
|
|
//TXT日志目录
|
|
filePath = folderPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
|
|
|
//判断是否存在文件夹
|
|
if (!System.IO.Directory.Exists(folderPath))
|
|
{
|
|
//创建文件夹
|
|
Directory.CreateDirectory(folderPath);
|
|
}
|
|
inPut(log);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 写入日志事件
|
|
/// </summary>
|
|
/// <param name="log"></param>
|
|
private static void inPut(string log)
|
|
{
|
|
//判断是否存在此TXT文件
|
|
if (!System.IO.File.Exists(filePath))
|
|
{
|
|
FileStream fs1 = new FileStream(filePath, FileMode.Create, FileAccess.Write);//创建写入文件
|
|
StreamWriter sw = new StreamWriter(fs1);
|
|
sw.WriteLine(log);//开始写入值
|
|
sw.Close();
|
|
fs1.Close();
|
|
}
|
|
else
|
|
{
|
|
FileStream fs1 = new FileStream(filePath, FileMode.Append, FileAccess.Write);//获取文件尾行
|
|
StreamWriter sw = new StreamWriter(fs1);
|
|
sw.WriteLine(log);//开始写入值
|
|
sw.Close();
|
|
fs1.Close();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|