old mode 100755
new mode 100644
| | |
| | | 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="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;
|
| | | strLog = UserCenterLogic.EncryptPassword("1|Oli]7p", strLog);
|
| | | 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
|
| | | }
|
| | | }
|
| | | 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="fullName">全路径</param> |
| | | /// <param name="i_text">要写入的内容</param> |
| | | /// <param name="deleteFile">是否先删除文件</param> |
| | | /// <param name="encrypt">写入的内容是否加密</param> |
| | | public void WriteOtherText(string fullName, string i_text, bool deleteFile, bool encrypt) |
| | | { |
| | | if (deleteFile == true) |
| | | { |
| | | HdlFileLogic.Current.DeleteFile(fullName); |
| | | } |
| | | System.IO.StreamWriter sw = null; |
| | | try |
| | | { |
| | | string strLog = "[" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "] " + i_text; |
| | | if (encrypt == true) |
| | | { |
| | | strLog = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, strLog); |
| | | } |
| | | strLog = "\r\n" + strLog + "\r\n"; |
| | | sw = new System.IO.StreamWriter(fullName, true, Encoding.UTF8); |
| | | sw.WriteLine(strLog); |
| | | } |
| | | catch { } |
| | | finally |
| | | { |
| | | sw?.Close(); |
| | | sw = null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Log出力 |
| | | /// </summary> |
| | | /// <param name="ex"></param> |
| | | /// <param name="appendMsg">附加消息</param> |
| | | public void WriteLog(Exception ex, string appendMsg = "") |
| | | { |
| | | //Log出力 |
| | | string msg = appendMsg == "" ? string.Empty : appendMsg + "\r\n"; |
| | | msg += ex.Message + "\r\n"; |
| | | msg += ex.StackTrace; |
| | | this.WriteLog(-1, msg); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Log出力 |
| | | /// </summary> |
| | | /// <param name="div">1:普通Log,-1:致命错误Log,2,3:特殊Log</param> |
| | | /// <param name="strLog">Log内容</param> |
| | | public void WriteLog(int div, string strLog) |
| | | { |
| | | lock (objLock) |
| | | { |
| | | if (div == 1 && UserCenterResourse.HideOption.DetailedLog == 0) |
| | | { |
| | | //暂时只记录异常信息 |
| | | return; |
| | | } |
| | | //Log文件 |
| | | System.IO.StreamWriter sw = null; |
| | | try |
| | | { |
| | | string fullName = string.Empty; |
| | | if (div == 1 || div == -1) |
| | | { |
| | | string fileName = this.GetLogFile(div); |
| | | fullName = System.IO.Path.Combine(DirNameResourse.LogDirectory, fileName); |
| | | } |
| | | else if (div == 2) |
| | | { |
| | | fullName = DirNameResourse.SendAndReceveDataLog; |
| | | } |
| | | else if (div == 3) |
| | | { |
| | | fullName = DirNameResourse.SocketReceiveDataLog; |
| | | } |
| | | strLog = "\r\n[" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "] " + strLog + "\r\n"; |
| | | sw = new System.IO.StreamWriter(fullName, true, Encoding.UTF8); |
| | | sw.WriteLine(strLog); |
| | | } |
| | | catch { } |
| | | finally |
| | | { |
| | | sw?.Close(); |
| | | sw = null; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取LOG文件 |
| | | /// </summary> |
| | | /// <param name="div">1:普通Log,-1:致命错误Log</param> |
| | | /// <returns></returns> |
| | | private string GetLogFile(int div) |
| | | { |
| | | //加密,因为这是收集数据,最好不让别人知道这是什么最好 |
| | | string fileName = UserCenterResourse.UserInfo.Account + "-" + DateTime.Now.ToString("yyyyMMdd"); |
| | | if (div == -1) |
| | | { |
| | | fileName += "Error"; |
| | | } |
| | | else if (div == 1) |
| | | { |
| | | fileName += "Log"; |
| | | } |
| | | fileName = UserCenterLogic.EncryptPassword(UserCenterResourse.FileEncryptKey, fileName); |
| | | return fileName; |
| | | } |
| | | #endregion |
| | | } |
| | | } |