using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// Log逻辑
|
/// </summary>
|
public class HdlLogLogic
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// Log逻辑
|
/// </summary>
|
private static HdlLogLogic m_Current = null;
|
/// <summary>
|
/// Log逻辑
|
/// </summary>
|
public static HdlLogLogic Current
|
{
|
get
|
{
|
if (m_Current == null)
|
{
|
m_Current = new HdlLogLogic();
|
}
|
return m_Current;
|
}
|
}
|
|
/// <summary>
|
/// 锁
|
/// </summary>
|
private object objLock = new object();
|
|
#endregion
|
|
#region ■ Log出力____________________________
|
|
/// <summary>
|
/// Log出力
|
/// </summary>
|
/// <param name="ex"></param>
|
public void WriteLog(Exception ex)
|
{
|
//Log出力
|
string msg = ex.Message + "\r\n";
|
msg += ex.StackTrace;
|
this.WriteLog(-1, msg);
|
}
|
|
/// <summary>
|
/// Log出力
|
/// </summary>
|
/// <param name="div">1:普通Log,-1:致命错误Log</param>
|
/// <param name="strLog">Log内容</param>
|
public void WriteLog(int div, string strLog)
|
{
|
lock (objLock)
|
{
|
//if (div != -1)
|
//{
|
// //暂时只记录异常信息
|
// return;
|
//}
|
//Log文件
|
string fileName = this.GetLogFile(div);
|
string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.LogDirectory, fileName);
|
|
strLog = "[" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "] " + strLog + "\r\n";
|
var sw = new System.IO.StreamWriter(fullName, true, Encoding.UTF8);
|
sw.WriteLine(strLog);
|
sw.Close();
|
sw = null;
|
}
|
}
|
|
/// <summary>
|
/// 获取LOG文件
|
/// </summary>
|
/// <param name="div">1:普通Log,-1:致命错误Log</param>
|
/// <returns></returns>
|
private string GetLogFile(int div)
|
{
|
//加密,因为这是收集数据,最好不让别人知道这是什么最好
|
string fileName = DateTime.Now.ToString("yyyyMMdd");
|
if (div == -1)
|
{
|
fileName += "Log";
|
}
|
else if (div == 1)
|
{
|
fileName += "Error";
|
}
|
fileName = UserCenterLogic.EncryptPassword("4^Olh_3f", fileName);
|
return fileName;
|
}
|
#endregion
|
}
|
}
|