Exemple #1
0
        /// <summary>
        /// 生成日志文件全路径
        /// yyyy_MM_dd_HH_mm
        /// </summary>
        /// <param name="logType"></param>
        /// <returns></returns>
        private static string GenerateFilePath(LoggingType logType)
        {
            var token      = DateTime.Now.ToString("yyyy_MM_dd_HH_mm");// + "_" + Guid.NewGuid().ToString().Split('-')[0];
            var logTypeDir = logType.ToString();

            return(string.Format("{0}\\{1}\\{2}.log", LogDir, logTypeDir, token));
        }
Exemple #2
0
        private void WriteEntry(LoggingType type, string logEntryMessage)
        {
            ReadLog();
            logEntryMessage = "\n" + DateTime.Now.ToString("dd-MM-yyyy H:mm:ss\t[") +
                              type.ToString() + "] " + logEntryMessage;
            this._logText += logEntryMessage;

            File.WriteAllText(this._filePath, this._logText);
        }
Exemple #3
0
        /// <summary>
        /// Writes the specified message to the console
        /// </summary>
        /// <param name="type">The type of message</param>
        /// <param name="sender">The sender of the message</param>
        /// <param name="message">The message itself</param>
        public void Log(LoggingType type, object sender, string message)
        {
            string line = string.Format("[{0}:{1}]: {2}", type.ToString()[0], sender.GetType().FullName, message);

            Console.WriteLine(line);
            if (writer != null)
            {
                writer.WriteLine(line);
                writer.Flush();
            }
        }
Exemple #4
0
        /// <summary>
        /// Writes the specified message to the console
        /// </summary>
        /// <param name="type">The type of message</param>
        /// <param name="sender">The sender of the message</param>
        /// <param name="message">The message itself</param>
        public void Log(LoggingType type, object sender, string message)
        {
            var line = string.Format("[{0}:{1}]: {2}", type.ToString()[0], null == sender ? "NOWHERE" : sender.GetType().FullName, message);

            Console.WriteLine(line);
            if (writer == null)
            {
                return;
            }
            writer.WriteLine(line);
            writer.Flush();
        }
Exemple #5
0
 /// <summary>
 /// Writes the specified message with the specified type to the log
 /// </summary>
 /// <param name="type">The type of logging message</param>
 /// <param name="msg">The message to write</param>
 public void Log(LoggingType type, string msg)
 {
     if (this.Logger != null)
     {
         this.Logger.Log(type, this, string.Format("{0}{1}", !string.IsNullOrEmpty(this.ComponentName) ? this.ComponentName + ": " : string.Empty, msg));
     }
     else
     {
         string str = string.Format("{0}: {1}", type.ToString(), msg);
         try { Debug.WriteLine(str); }
         catch { Console.WriteLine(str); }
     }
 }
Exemple #6
0
        public void CreateWithFileInfoAllLoggingTypes(LoggingType lt)
        {
            string fullLogFilename = logPath + logFile + ".log";
            var    logging         = new EMLogging(logPath, logFile);

            Assert.IsNotNull(logging);

            logging.Log("Test", lt);
            Assert.IsTrue(File.Exists(fullLogFilename));

            string line1 = File.ReadLines(fullLogFilename).First();

            Assert.IsTrue(line1.Contains(lt.ToString() + "::"));
        }
Exemple #7
0
        /// <summary>
        /// Write an entry in to the log file
        /// </summary>
        /// <param name="logData">Entry into the log file</param>
        /// <param name="logType">Type of the log entry</param>
        public void Log(string logData, LoggingType logType = LoggingType.Info)
        {
            if (string.IsNullOrEmpty(_LogPath) || string.IsNullOrEmpty(_LogName))
            {
                throw new Exception("Path and/or name for log file not set");
            }

            string logDataPrefix = logType.ToString() + "::";

            string        timeStamp        = DateTime.Now.ToString() + " - ";
            string        formattedLogLine = $"{(!TimeStamp ? "" : timeStamp)}{logDataPrefix + logData}";
            List <string> logLine          = new List <string> {
                formattedLogLine
            };

            string dateStamp = "." + DateTime.Now.ToString("yyyyMMdd");
            string fileName  = $"{_LogName}{(!DateStamp ? "" : dateStamp)}.log";

            File.AppendAllLines(_LogPath + fileName, logLine);
        }
 /// <summary>
 /// <see cref="ILogger.Log(LoggingType,object,string)"/>
 /// </summary>
 /// <param name="type"></param>
 /// <param name="sender"></param>
 /// <param name="message"></param>
 public void Log(LoggingType type, object sender, string message)
 {
     this.WriteLine(string.Format("[{0}:{1}]: {2}", type.ToString()[0], sender.GetType().FullName, message));
 }
Exemple #9
0
 /// <summary>
 /// <see cref="ILogger.Log(LoggingType,object,string)"/>
 /// </summary>
 /// <param name="type"></param>
 /// <param name="sender"></param>
 /// <param name="message"></param>
 public void Log(LoggingType type, object sender, string message)
 {
     this.WriteLine(string.Format("[{1}][{0}]: {2}", DateTime.Now, type.ToString()[0], message));
 }