45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace WCS
|
|||
|
|
{
|
|||
|
|
public class WriteSysLog
|
|||
|
|
{
|
|||
|
|
private static string LogName2 = "Log";
|
|||
|
|
/// <summary>
|
|||
|
|
/// 写日志
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="strLog"></param>
|
|||
|
|
public static void SysLog(string strLog)
|
|||
|
|
{
|
|||
|
|
lock ("SysLog")
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
strLog = strLog + Environment.NewLine;
|
|||
|
|
DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\" + LogName2);
|
|||
|
|
if (di.Exists == false)
|
|||
|
|
{
|
|||
|
|
di.Create();
|
|||
|
|
}
|
|||
|
|
string logFileName;
|
|||
|
|
logFileName = AppDomain.CurrentDomain.BaseDirectory + "\\" + LogName2 + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
|
|||
|
|
if (File.Exists(logFileName))
|
|||
|
|
{
|
|||
|
|
FileInfo fi = new FileInfo(logFileName);
|
|||
|
|
}
|
|||
|
|
StreamWriter sw = null;
|
|||
|
|
FileStream fs = new FileStream(logFileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
|
|||
|
|
sw = new StreamWriter(fs);
|
|||
|
|
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + "||" + strLog);
|
|||
|
|
sw.Close();
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|