using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web;
namespace iWareWebservice.AppUtil
{
public class LogHelper
{
private readonly string _logPath = ConfigurationManager.AppSettings["LogDir"].ToString();
public static object Lock = new object();
public static LogHelper Instance = null;
///
///获取单例的方法
///
///单例实体
public static LogHelper GetInstance()
{
if (Instance == null)
{
lock (Lock)
{
if (Instance == null)
{
Instance = new LogHelper();
}
}
}
return Instance;
}
///
/// 添加日志
///
/// 日志目录
/// 方法名
/// 内容格式
/// 内容参数
public void WriteLog(string methodName, string format, params object[] args)
{
try
{
if (!Directory.Exists(_logPath))
{
Directory.CreateDirectory(_logPath);
}
string message = string.Format("【{0}】【{1}】{2}\r\n", DateTime.Now.ToString("HH:mm:ss"), methodName,string.Format(format, args));
File.AppendAllText(Path.Combine(_logPath, DateTime.Now.ToString("yyyyMMdd") + ".txt"), message);
}
catch (Exception) { }
}
}
}