Esempio n. 1
0
        /// <summary>
        /// 创建日志文件名称
        /// </summary>
        /// <param name="path">日志路径</param>
        /// <param name="logType">日志类型</param>
        /// <returns></returns>
        private static string CreateLogFile(string path, enLogType logType)
        {
            string dir = path;

            if (Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }

            //string dirMonth = dir + @"\" + DateTime.Now.Year + DateTime.Now.Month.ToString("00");
            //if (Directory.Exists(dirMonth) == false)
            //    Directory.CreateDirectory(dirMonth);

            string filePre = dir + @"\" + DateTime.Now.Year + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00");
            string fileDay = "";
            int    index   = 1;

            while (true)
            {
                FileInfo fi;
                string   fullname = null;
                if (logType == enLogType.eErr)
                {
                    fullname = filePre + "_" + index.ToString() + ".err";
                }
                else if (logType == enLogType.eInfo)
                {
                    fullname = filePre + "_" + index.ToString() + ".ifr";
                }
                else if (logType == enLogType.eCli)
                {
                    fullname = filePre + "_" + index.ToString() + ".cli";
                }

                if (File.Exists(fullname) == true)
                {
                    fi = new FileInfo(fullname);
                    //判断文件大小是否超过10M
                    if (fi.Length / 1024 / 1024 >= 10)
                    {
                        index++;
                        continue;
                    }
                    else
                    {
                        fileDay = fullname;
                        break;
                    }
                }
                else
                {
                    fileDay = fullname;
                    break;
                }
            }

            return(fileDay);
        }
Esempio n. 2
0
        internal LogMessage(string logText, enLogType logType, string logFileName, Guid sessionID)
        {
            ThreadID  = Thread.CurrentThread.ManagedThreadId;
            TimeStamp = DateTime.Now;

            LogText     = logText;
            LogType     = logType;
            LogFileName = logFileName;
            SessionID   = sessionID;
        }
Esempio n. 3
0
 public void Write(string logText, enLogType logType)
 {
     // Only add to the queue if we're supporting this logging type
     if (LogLevel >= logType && LogLevel != enLogType.None)
     {
         lock (_queueSync) {
             _messageQueue.Enqueue(new LogMessage(logText, logType, LogConnectionString, SessionID));
         }
     }
 }
Esempio n. 4
0
        public static void EnableLog(Type EntityType, enLogType LogType)
        {
            EnableLogAttribute RetVal;

            if (!LogList.TryGetValue(EntityType.Name, out RetVal))
            {
                RetVal = new EnableLogAttribute(LogType);
                LogList.Add(EntityType.Name, RetVal);
            }
            RetVal.LogType = LogType;
        }
Esempio n. 5
0
        public void Send(enLogType logType, T dataValue)
        {
            this._logType   = logType;
            this._dataValue = dataValue;

            this._currentState = _senderState["PrepareState"];
            this._currentState.Execute();

            this._currentState = _senderState["ProcessState"];
            this._currentState.Execute();
        }
Esempio n. 6
0
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="logType">日志类型</param>
        /// <param name="log">日志信息</param>
        /// <param name="newline">是否在新的一行中记录</param>
        private static void WriteLog(enLogType logType, string log, bool newline = true)
        {
            string fileName = null;

            try
            {
                // 固定每天凌晨1点对之前的日志进行压缩
                if (DateTime.Now.Hour == cfgLogNeatenTime &&
                    LastCompressDate.Day != DateTime.Now.Day &&
                    !bNeatening)
                {
                    Thread NeatenLogger = new Thread(NeatenLog);
                    NeatenLogger.Priority = ThreadPriority.Normal;
                    bNeatening            = true;
                    NeatenLogger.Start();
                }

                if (logType == enLogType.eErr)
                {
                    fileName = CreateLogFile(pathErr, logType);
                }
                else if (logType == enLogType.eInfo)
                {
                    fileName = CreateLogFile(pathInf, logType);
                }
                else if (logType == enLogType.eCli)
                {
                    fileName = CreateLogFile(pathCLI, logType);
                }
                lock (thisLock)
                {
                    using (StreamWriter sw = new StreamWriter(fileName, true))
                    {
                        if (newline)
                        {
                            sw.WriteLine(log);
                        }
                        else
                        {
                            sw.Write(" " + log);
                        }
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void Should_TopElementMustBeAPI_When_ExecuteRecordsIsEmpty()
        {
            //Arrange
            enLogType expect = enLogType.API, actual;

            this._ctx.DataConnection.Fetch <object>(Arg.Any <string>()).Returns <object>(null);

            //Act
            this._ctx.Initial();
            this._ctx.ReceiveMsg();
            actual = this._ctx.ExecutedRecords.Dequeue();

            //Assert
            actual.Should().Be(expect);
        }
        public void Should_TopElementMustBeBO_When_AddNewOne_And_APIAndBOAreInExecutedRecords()
        {
            //Arrange
            enLogType expect = enLogType.BO, actual;

            this._ctx.ExecutedRecords.Enqueue(enLogType.API);
            this._ctx.ExecutedRecords.Enqueue(enLogType.BO);
            this._ctx.DataConnection.Fetch <object>(Arg.Any <string>()).Returns <object>(null);

            //Act
            this._ctx.Initial();
            this._ctx.ReceiveMsg();
            actual = this._ctx.ExecutedRecords.Dequeue();

            //Assert
            actual.Should().Be(expect);
        }
Esempio n. 9
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="layer">协议栈分层</param>
        /// <param name="type">日志类型</param>
        /// <param name="content">日志内容</param>
        /// <param name="newline">是否在新的一行中记录日志</param>
        public LogElement(enLogLayer layer, enLogType type, string content, bool newline = true)
        {
            LogTime = DateTime.Now.ToString("MM/dd HH:mm:ss:fff");

            LogLayer = layer;
            LogType  = type;
            if (content == null)
            {
                LogContent = string.Empty;
            }
            else
            {
                LogContent = content;
            }

            NewLine = newline;
        }
Esempio n. 10
0
    private static void log(string _logFileName, object _class, enLogType logType, object[] values)
    {
        if (disable == true)
        {
            return;
        }

        string logStr = GetDebugString(_class, values);

        if (Application.isEditor)
        {
            if (logType == enLogType.Error)
            {
                Debug.LogError(logStr);
            }
            else if (logType == enLogType.Warning)
            {
                Debug.LogWarning(logStr);
            }
            else if (logType == enLogType.Fatal)
            {
                Debug.LogError(logStr);
            }
            else
            {
                Debug.Log(logStr);
            }
        }

        try {
            string fileName = UnityEngine.Application.persistentDataPath + "/Log/Unity/" + _logFileName + ".log";

            logStr += "\n";

            using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write)) {
                byte[] data = new System.Text.UTF8Encoding().GetBytes(logStr);
                fs.Write(data, 0, data.Length);
                fs.Flush();
                fs.Close();
            }
        } catch (Exception e) {
            Debug.LogError(e);
        }
    }
        public override void Execute()
        {
            //step1. pick-up log type
            IEnumerable <enLogType> executed = this.ExecutedRecords.ToArray();
            enLogType candidate = _logTypes.Except(executed).First();

            if (executed.Count() > 1)
            {
                this.ExecutedRecords.Dequeue();      //Pop-up oldest
            }
            this.ExecutedRecords.Enqueue(candidate); //Push-In newest

            //step2. generate key pattern
            this.Key = string.Format(@"{{{0}/{1}}}:*", candidate.ToString(), this.NodeId);
            IEnumerable <T> objs = this.DataConnection.Fetch <T>(this.Key);

            if (objs != null)
            {
                this.DataObjs.AddRange(objs);
            }
        }
        private static void writeToLogsFile(string srLog, enLogType whichLog)
        {
            switch (whichLog)
            {
            case enLogType.ByPassedUrl:
                lock (_lock_swLogs)
                {
                    swLogs.WriteLine(srLog + "\t" + DateTime.Now + "\r\n");
                }
                break;

            case enLogType.FoundUrl:
                lock (_lock_swNewFoundUrls)
                {
                    swNewFoundUrls.WriteLine(srLog + "\t" + DateTime.Now + "\r\n");
                }
                break;

            default:
                break;
            }
        }
Esempio n. 13
0
 public static void EnableLog <TEntity>(enLogType LogType)
     where TEntity : BusinessEntity
 {
     EnableLog(typeof(TEntity), LogType);
 }
 public EnableLogAttribute()
 {
     LogType = enLogType.LogAll;
 }
Esempio n. 15
0
 public void Write(string logText, enLogType logType)
 {
     throw new NotImplementedException();
 }
 public EnableLogAttribute(enLogType LogType)
 {
     this.LogType = LogType;
 }
Esempio n. 17
0
        public void AddLog(string message, enLogType type)
        {
            var logElement = new LogElement(message, type);

            AddLog(logElement);
        }
Esempio n. 18
0
 private void AddLogFromAsync(string message, enLogType logType)
 {
     autoSendObject.Dispatcher.Invoke(() => {
         autoSendObject.LogService.AddLog(message, logType);
     });
 }
Esempio n. 19
0
 public void Write(string logText, enLogType logType)
 {
     // Do nothing
 }
Esempio n. 20
0
        private static void SaveLogInfo(enLogType logType, string messageFormat, Exception ex, params object[] args)
        {
            object stackTrace = DBNull.Value;
            object LoggedInUserId = DBNull.Value;
            object url = DBNull.Value;
            object refUrl = DBNull.Value;
            object session = DBNull.Value;
            object methodName = DBNull.Value;
            bool hasError = false;
            StringBuilder stackInfo = new StringBuilder();
            var current = HttpContext.Current;

            if (current != null && current.Request != null)
            {
                url = current.Request.Url.ToString();
                if (current.Request.UrlReferrer != null)
                    refUrl = current.Request.UrlReferrer.ToString();
            }

            string userid = HttpContext.Current.User.Identity.Name;
            if (string.IsNullOrEmpty(userid))
            {
              

                try
                {
                    session = new JavaScriptSerializer().Serialize(userid);
                }
                catch (Exception exSer)
                {
                    stackInfo.AppendLine("Session Values Serialization Error");
                    stackInfo.AppendLine(exSer.Message);
                    if (exSer.InnerException != null)
                    {
                        stackInfo.AppendLine();
                        stackInfo.AppendLine(exSer.InnerException.Message);
                        stackInfo.AppendLine();
                        stackInfo.AppendLine();
                    }
                }
            }
            if (ex != null)
            {
                hasError = true;
                stackInfo.AppendLine("Error Message:");
                stackInfo.AppendLine(ex.Message);
                stackInfo.AppendLine();

                stackInfo.AppendLine("Source:");
                stackInfo.AppendLine(ex.Source);
                stackInfo.AppendLine();

                stackInfo.AppendLine("Stack Trace:");
                stackInfo.AppendLine(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    stackInfo.AppendLine();
                    stackInfo.AppendLine("Inner Exception");
                    stackInfo.AppendLine();

                    stackInfo.AppendLine("Error Message:");
                    stackInfo.AppendLine(ex.InnerException.Message);
                    stackInfo.AppendLine();

                    stackInfo.AppendLine("Source:");
                    stackInfo.AppendLine(ex.InnerException.Source);
                    stackInfo.AppendLine();

                    stackInfo.AppendLine("Stack Trace:");
                    stackInfo.AppendLine(ex.InnerException.StackTrace);
                }



            }
            if (hasError) stackTrace = stackInfo.ToString();

            try
            {
                var frames = new System.Diagnostics.StackTrace().GetFrames();
                System.Diagnostics.StackFrame frame = null;
                for (var i = 1; i < frames.Length; i++)
                {
                    if (frames[i].GetMethod().Name != "Info" && frames[i].GetMethod().Name != "Error")
                    {
                        frame = frames[i];
                        break;
                    }
                }
                if (frame != null)
                {
                    var stackMethod = frame.GetMethod();
                    methodName = stackMethod.ReflectedType.FullName + "." + stackMethod.Name;
                }
                using (var objDBContext = new WizzDataContext())
                {
                    objDBContext.usp_SaveLog((int)logType, Convert.ToString(messageFormat), Convert.ToString(stackTrace), Convert.ToString(methodName), 0, Convert.ToString(url), Convert.ToString(refUrl), Convert.ToString(session));
                    objDBContext.SubmitChanges();
                }
            }
            catch (Exception logEx)
            {
                _logger.Error("Error occurd while saving error log in database", logEx);
            }
           
        }
Esempio n. 21
0
 public void SendMsg(enLogType logType, DTO msg)
 {
     this._sender.Send(logType, msg);
 }
Esempio n. 22
0
 public LogElement(string message, enLogType logType)
 {
     Message = message;
     LogType = logType;
     Date    = DateTime.Now;
 }