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;
|
|
///<summary>
|
///获取单例的方法
|
///</summary>
|
///<returns>单例实体</returns>
|
public static LogHelper GetInstance()
|
{
|
|
if (Instance == null)
|
{
|
lock (Lock)
|
{
|
if (Instance == null)
|
{
|
Instance = new LogHelper();
|
}
|
}
|
}
|
return Instance;
|
}
|
|
/// <summary>
|
/// 添加日志
|
/// </summary>
|
/// <param name="folder">日志目录</param>
|
/// <param name="methodName">方法名</param>
|
/// <param name="format">内容格式</param>
|
/// <param name="args">内容参数</param>
|
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) { }
|
}
|
}
|
}
|