You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace n5coredll
{
public class LogUtil
{
private static String mLogPath;
private static LogUtil mInstance;
public static LogUtil getInstance()
{
if (mInstance == null)
mInstance = new LogUtil();
return mInstance;
}
public void setLogPath(String logPath)
{
if (logPath.EndsWith(@"\"))
mLogPath = logPath;
else
mLogPath = logPath + @"\";
}
private String getCurLogFile()
{
StringBuilder txnIdSb = new StringBuilder();
DateTime dt = DateTime.Now;
return ("n5dll" + "_" + dt.ToString("yyyyMMdd") +".log");
}
public void addRepeatLog(string logInfo)
{
try
{
String path = mLogPath + getCurLogFile();
//path = @"C:\Users\rexli\AppData\Local\Temp\test.log";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:ffff") + " [LOGGER] " + logInfo);
sw.Flush();
sw.Close();
}
}
else
{
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:ffff") + " [LOGGER] " + logInfo);
sw.Flush();
sw.Close();
}
}
// Console.WriteLine(logInfo);
}
catch (Exception err)
{
Console.WriteLine("Exception = " + err);
}
}
}
}