Exemplo n.º 1
0
        /// <summary>
        /// Add line to Log
        /// </summary>
        /// <param name="text"></param>
        /// <param name="file"></param>
        /// <param name="member"></param>
        /// <param name="lineNumber"></param>
        public static void Log(string text, LogLineType type = LogLineType.Notification, [CallerFilePath] string filename = "", [CallerMemberName] string member = "", [CallerLineNumber] int lineNumber = 0)
        {
            try
            {
                string[] lines = text.Split(new string[] { "\r\n", "\n", Environment.NewLine }, StringSplitOptions.None);
                foreach (var line in lines)
                {
                    var queueLine = new Line();
                    queueLine.Text      = line;
                    queueLine.Type      = type;
                    queueLine.Timestamp = DateTime.Now;

                    var assembly = Assembly.GetCallingAssembly();

                    queueLine.Assembly   = assembly.FullName;
                    queueLine.Filename   = filename;
                    queueLine.Member     = member;
                    queueLine.LineNumber = lineNumber;

                    logQueue.AddLineToQueue(queueLine);
                    Console.WriteLine(line);
                }
            }
            catch (Exception ex) { }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Writes a line to the log file. Creates a new timestamped log file if none exists.
 /// </summary>
 /// <param name="LineType">The type of line to log,</param>
 /// <param name="Text">The text to be on the line.</param>
 public static void WriteLine(LogLineType LineType, String Text)
 {
     if (LogWriter == null) {
         if (!Directory.Exists("Logs")) {
             Directory.CreateDirectory("Logs");
         }
         LogWriter = new StreamWriter("Logs\\" + DateTime.Now.ToString("yyyyMMdd-hhmmss") + ".log");
         LogWriter.AutoFlush = true;
     }
     String LogString = DateTime.Now.ToString("[MM/dd/yy @ hh:mm:ss.f]") + " [";
     if (LineType == LogLineType.Error) { LogString += "ERROR"; } else if (LineType == LogLineType.Warning) { LogString += " WARN"; } else if (LineType == LogLineType.Information) { LogString += " INFO"; } else if (LineType == LogLineType.Debug) { LogString += "DEBUG"; }
     LogString += "] " + Text;
     if (Config.Option["LogLevel"] == "DEBUG") {
         LogWriter.WriteLine(LogString);
     } else if (Config.Option["LogLevel"] == "INFORMATION") {
         if ((LineType == LogLineType.Information) || (LineType == LogLineType.Warning) || (LineType == LogLineType.Error)) {
             LogWriter.WriteLine(LogString);
         }
     } else if (Config.Option["LogLevel"] == "WARNING") {
         if ((LineType == LogLineType.Warning) || (LineType == LogLineType.Error)) {
             LogWriter.WriteLine(LogString);
         }
     } else if (Config.Option["LogLevel"] == "ERROR") {
         if (LineType == LogLineType.Error) {
             LogWriter.WriteLine(LogString);
         }
     }
     AdminConsole.WriteLine(LineType, Text);
 }
Exemplo n.º 3
0
        private static string ReadOutputLogText(LogLineType type, string applicationName, DateTime timestamp)
        {
            string result = null;

            XmlNode[] nodes = ReadOutputLogXml(type, applicationName, timestamp);
            if (nodes != null)
            {
                result = "";

                foreach (XmlNode lineNode in nodes)
                {
                    string t = XML.Attributes.Get(lineNode, "timestamp");
                    if (t != null)
                    {
                        DateTime date = DateTime.MinValue;
                        if (DateTime.TryParse(t, out date))
                        {
                            if (date > timestamp)
                            {
                                result += lineNode.InnerText + Environment.NewLine;
                            }
                        }
                    }
                }
            }

            return(result);
        }
 /// <summary>
 /// Writes a line to the Admin Console.
 /// </summary>
 /// <param name="LineType">Type of line to write.</param>
 /// <param name="Text">Text to write on the line.</param>
 public static void WriteLine(LogLineType LineType, String Text)
 {
     String LogString = DateTime.Now.ToString("[hh:mm:ss.f]") + " [";
     if (LineType == LogLineType.Error) { LogString += "ERROR"; } else if (LineType == LogLineType.Warning) { LogString += " WARN"; } else if (LineType == LogLineType.Information) { LogString += " INFO"; } else if (LineType == LogLineType.Debug) { LogString += "DEBUG"; }
     LogString += "] " + Text + "\n";
     Write(LineType, LogString);
 }
Exemplo n.º 5
0
            private void HandleWorkUnitRunning(LogLine logLine)
            {
                // If we've already seen a WorkUnitRunning line, ignore this one
                if (_currentLineType == LogLineType.WorkUnitRunning)
                {
                    return;
                }

                // Not Checking the Queue Slot - we don't care if we found a valid slot or not
                if (_unitIndexData.ProcessingIndex > -1)
                {
                    EnsureUnitRunExists(_unitIndexData.ProcessingIndex, _unitIndexData.QueueSlotIndex);
                }
                else if (_unitIndexData.WorkingIndex > -1)
                {
                    EnsureUnitRunExists(_unitIndexData.WorkingIndex, _unitIndexData.QueueSlotIndex);
                }
                else if (_unitIndexData.StartIndex > -1)
                {
                    EnsureUnitRunExists(_unitIndexData.StartIndex, _unitIndexData.QueueSlotIndex);
                }
                else
                {
                    EnsureUnitRunExists(logLine.Index, _unitIndexData.QueueSlotIndex);
                }

                _currentLineType = logLine.LineType;

                // Re-initialize Values
                _unitIndexData.Initialize();
            }
Exemplo n.º 6
0
        /// <summary>
        /// Add line to Log
        /// </summary>
        /// <param name="text"></param>
        /// <param name="file"></param>
        /// <param name="member"></param>
        /// <param name="lineNumber"></param>
        public static void Log(string text, LogLineType type = LogLineType.Notification, [CallerFilePath] string filename = "", [CallerMemberName] string member = "", [CallerLineNumber] int lineNumber = 0)
        {
            try
            {
                string[] lines = text.Split(new string[] { "\r\n", "\n", Environment.NewLine }, StringSplitOptions.None);
                foreach (var line in lines)
                {
                    var queueLine = new Line();
                    queueLine.Text = line;
                    queueLine.Type = type;
                    queueLine.Timestamp = DateTime.Now;

                    var assembly = Assembly.GetCallingAssembly();

                    queueLine.Assembly = assembly.FullName;
                    queueLine.Filename = filename;
                    queueLine.Member = member;
                    queueLine.LineNumber = lineNumber;

                    logQueue.AddLineToQueue(queueLine);
                    Console.WriteLine(line);
                }
            }
            catch (Exception ex) { }
        }
            /// <summary>
            /// Occurs after a line was read from the <see cref="TextReader"/> and returns a new <see cref="LogLine"/> object.
            /// </summary>
            /// <param name="line">The line read from the <see cref="TextReader"/>.</param>
            /// <param name="index">The index of the line read from the <see cref="TextReader"/>.</param>
            /// <returns>A new <see cref="LogLine"/> object from the string line and line index.</returns>
            protected override LogLine OnReadLine(string line, int index)
            {
                LogLineType lineType = LogLineTypeResolver.Resolve(line);
                LogLineTimeStampParserFunction timeStampParser = LogLineTimeStampParser.ParseTimeStamp;

                LogLineDataParserDictionary.TryGetValue(lineType, out LogLineDataParserFunction dataParser);
                return(new LazyLogLine(line, index, lineType, timeStampParser, dataParser));
            }
Exemplo n.º 8
0
        public static XmlNode[] ReadOutputLogXml(LogLineType type, string applicationName, DateTime timestamp)
        {
            XmlNode[] result = null;

            string path = "Log-" + FormatDate(DateTime.Now) + ".xml";

            switch (type)
            {
            case LogLineType.Debug: path = Path.Combine(OutputLogPath, OUTPUT_DIRECTORY_DEBUG, path); break;

            case LogLineType.Error: path = Path.Combine(OutputLogPath, OUTPUT_DIRECTORY_ERROR, path); break;

            case LogLineType.Notification: path = Path.Combine(OutputLogPath, OUTPUT_DIRECTORY_NOTIFICATION, path); break;

            case LogLineType.Warning: path = Path.Combine(OutputLogPath, OUTPUT_DIRECTORY_WARNING, path); break;
            }

            var doc = XML.Files.ReadDocument(path);

            if (doc != null)
            {
                if (doc.DocumentElement != null)
                {
                    var node = doc.DocumentElement.SelectSingleNode("//" + applicationName);
                    if (node != null)
                    {
                        var nodes = new List <XmlNode>();

                        foreach (XmlNode lineNode in node.ChildNodes)
                        {
                            string t = XML.Attributes.Get(lineNode, "timestamp");
                            if (t != null)
                            {
                                DateTime date = DateTime.MinValue;
                                if (DateTime.TryParse(t, out date))
                                {
                                    if (date > timestamp)
                                    {
                                        nodes.Add(lineNode);
                                    }
                                }
                            }
                        }

                        result = nodes.ToArray();
                    }
                }
            }

            return(result);
        }
Exemplo n.º 9
0
 private static string GetLogLineTypeName(LogLineType logLineType)
 {
     if (_LogLineTypeNameDictionary == null)
     {
         _LogLineTypeNameDictionary = new Dictionary <int, string>();
         var logLineTypeFields = typeof(LogLineType).GetFields(BindingFlags.Public | BindingFlags.Static);
         foreach (var fi in logLineTypeFields.Where(x => x.IsLiteral && !x.IsInitOnly))
         {
             int    fieldValue = (int)fi.GetValue(null);
             string fieldName  = fi.Name;
             _LogLineTypeNameDictionary.Add(fieldValue, fieldName);
         }
     }
     return(_LogLineTypeNameDictionary.ContainsKey(logLineType) ? _LogLineTypeNameDictionary[logLineType] : null);
 }
Exemplo n.º 10
0
        private static void CleanFiles(int days, LogLineType type)
        {
            string path = null;

            switch (type)
            {
            case LogLineType.Debug: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_DEBUG); break;

            case LogLineType.Error: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_ERROR); break;

            case LogLineType.Notification: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_NOTIFICATION); break;

            case LogLineType.Warning: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_WARNING); break;
            }

            if (days == 0)
            {
                // Delete everything
                if (path != null && !Directory.Exists(path))
                {
                    Directory.Delete(path, true);
                }
            }
            else
            {
                // Only delete files older than the days set in parameter
                DateTime threshold = DateTime.Now - TimeSpan.FromDays(days);

                if (path != null && Directory.Exists(path))
                {
                    string[] filePaths = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
                    if (filePaths.Length > 0)
                    {
                        foreach (var filePath in filePaths)
                        {
                            var fileInfo = new FileInfo(filePath);
                            if (fileInfo != null)
                            {
                                if (fileInfo.LastWriteTime < threshold)
                                {
                                    File.Delete(filePath);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
            private void HandleWorkUnitProcessing(LogLine logLine)
            {
                // If we have not found a ProcessingIndex (== -1) then set it.
                // Otherwise, if ProcessingIndex (!= -1) and a CoreDownloadIndex
                // has been observed and is greater than the current ProcessingIndex,
                // then update the ProcessingIndex to bypass the CoreDownload section
                // of the log file.
                if (_unitIndexData.ProcessingIndex == -1 ||
                    (_unitIndexData.ProcessingIndex != -1 &&
                     _unitIndexData.CoreDownloadIndex > _unitIndexData.ProcessingIndex))
                {
                    _unitIndexData.ProcessingIndex = logLine.Index;
                }

                _currentLineType = logLine.LineType;
            }
Exemplo n.º 12
0
 private void HandleWorkUnitWorking(LogLine logLine)
 {
     // This first check allows us to overlook the "+ Working ..." message
     // that gets written after a client is Paused.  We don't want to key
     // work unit positions based on this log entry.
     if (_currentLineType == LogLineType.WorkUnitPaused)
     {
         // Return to a Running state
         _currentLineType = LogLineType.WorkUnitRunning;
     }
     else
     {
         _unitIndexData.WorkingIndex = logLine.Index;
         _currentLineType            = logLine.LineType;
     }
 }
 /// <summary>
 /// Writes an chunk of text to the Admin Console.
 /// </summary>
 /// <param name="LineType">Type of line to write.</param>
 /// <param name="Text">Text to write on the line.</param>
 public static void Write(LogLineType LineType, String Text)
 {
     if (Config.Option["ConsoleLogLevel"] == "DEBUG") {
         Console.Write(Text);
     } else if (Config.Option["ConsoleLogLevel"] == "INFORMATION") {
         if ((LineType == LogLineType.Information) || (LineType == LogLineType.Warning) || (LineType == LogLineType.Error)) {
             Console.Write(Text);
         }
     } else if (Config.Option["ConsoleLogLevel"] == "WARNING") {
         if ((LineType == LogLineType.Warning) || (LineType == LogLineType.Error)) {
             Console.Write(Text);
         }
     } else if (Config.Option["ConsoleLogLevel"] == "ERROR") {
         if (LineType == LogLineType.Error) {
             Console.Write(Text);
         }
     }
 }
Exemplo n.º 14
0
            private void HandleLogHeader(LogLine logLine)
            {
                // If the last line observed was a LogOpen or a LogHeader, return
                // and don't use this as a signal to add a new ClientRun.
                if (_currentLineType == LogLineType.LogOpen ||
                    _currentLineType == LogLineType.LogHeader)
                {
                    return;
                }

                // Otherwise, if we see a LogHeader and the preceding line was not
                // a LogOpen or a LogHeader, then we use this as a signal to create
                // a new ClientRun.  This is a backup option and I don't expect this
                // situation to happen at all if the log file is not corrupt.
                EnsureSlotRunExists(logLine.Index, FoldingSlot, true);

                _currentLineType = logLine.LineType;
            }
Exemplo n.º 15
0
        private void ProcessQueue(LogLineType type)
        {
            var lines = queue.FindAll(x => x.Type == type);

            if (lines != null && lines.Count > 0)
            {
                try
                {
                    if (!Directory.Exists(Logger.OutputLogPath))
                    {
                        Directory.CreateDirectory(Logger.OutputLogPath);
                    }

                    string filename = "Log-" + Logger.FormatDate(DateTime.Now) + ".log";

                    string path = null;

                    switch (type)
                    {
                    case LogLineType.Debug: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_DEBUG, filename); break;

                    case LogLineType.Error: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_ERROR, filename); break;

                    case LogLineType.Notification: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_NOTIFICATION, filename); break;

                    case LogLineType.Warning: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_WARNING, filename); break;
                    }

                    // Write to Log File
                    using (var stream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Write))
                    {
                        using (var writer = new StreamWriter(stream))
                        {
                            foreach (Line line in lines)
                            {
                                writer.WriteLine(line);
                            }
                        }
                    }
                }
                catch (Exception ex) { Console.WriteLine("ProcessQueue(LogLineType) :: Exception :: " + type.ToString() + " :: " + ex.Message); }
            }
        }
Exemplo n.º 16
0
        private void ReadChanged(LogLineType type)
        {
            DateTime time = DateTime.MinValue;

            switch (type)
            {
            case LogLineType.Debug: time = lastDebugTimestamp; break;

            case LogLineType.Error: time = lastErrorTimestamp; break;

            case LogLineType.Notification: time = lastNotificationTimestamp; break;

            case LogLineType.Warning: time = lastWarningTimestamp; break;
            }

            var nodes = Logger.ReadOutputLogXml(type, AppicationName, time);

            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    var line = Line.FromXmlNode(node);

                    switch (type)
                    {
                    case LogLineType.Debug: lastDebugTimestamp = line.Timestamp; break;

                    case LogLineType.Error: time = lastErrorTimestamp = line.Timestamp; break;

                    case LogLineType.Notification: time = lastNotificationTimestamp = line.Timestamp; break;

                    case LogLineType.Warning: time = lastWarningTimestamp = line.Timestamp; break;
                    }

                    line.Type = type;
                    if (LineAdded != null)
                    {
                        LineAdded(line);
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void ProcessQueue(LogLineType type)
        {
            var lines = queue.FindAll(x => x.Type == type);

            if (lines != null && lines.Count > 0)
            {
                try
                {
                    if (!Directory.Exists(Logger.OutputLogPath))
                    {
                        Directory.CreateDirectory(Logger.OutputLogPath);
                    }

                    string path = @"\Log-" + Logger.FormatDate(DateTime.Now) + ".xml";

                    switch (type)
                    {
                    case LogLineType.Debug: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_DEBUG, path); break;

                    case LogLineType.Error: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_ERROR, path); break;

                    case LogLineType.Notification: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_NOTIFICATION, path); break;

                    case LogLineType.Warning: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_WARNING, path); break;
                    }

                    // Create Log (XmlDocument)
                    XmlDocument doc = CreateDocument(path);

                    foreach (Line line in lines)
                    {
                        AddToLog(doc, line);
                    }

                    XML.Files.WriteDocument(doc, path);
                }
                catch (Exception ex) { Console.WriteLine("ProcessQueue(LogLineType) :: Exception :: " + type.ToString() + " :: " + ex.Message); }
            }
        }
Exemplo n.º 18
0
        private static void CleanFiles(int days, LogLineType type)
        {
            string path = null;
            switch (type)
            {
                case LogLineType.Debug: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_DEBUG); break;
                case LogLineType.Error: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_ERROR); break;
                case LogLineType.Notification: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_NOTIFICATION); break;
                case LogLineType.Warning: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_WARNING); break;
            }

            if (days == 0)
            {
                // Delete everything
                if (path != null && !Directory.Exists(path)) Directory.Delete(path, true);
            }
            else
            {
                // Only delete files older than the days set in parameter
                DateTime threshold = DateTime.Now - TimeSpan.FromDays(days);

                if (path != null && Directory.Exists(path))
                {
                    string[] filePaths = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
                    if (filePaths.Length > 0)
                    {
                        foreach (var filePath in filePaths)
                        {
                            var fileInfo = new FileInfo(filePath);
                            if (fileInfo != null)
                            {
                                if (fileInfo.LastWriteTime < threshold) File.Delete(filePath);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
 protected override void HandleWorkUnitStart(LogLine logLine)
 {
     _unitIndexData.StartIndex = logLine.LineIndex;
      _currentLineType = logLine.LineType;
 }
Exemplo n.º 20
0
        protected override void HandleWorkUnitRunning(LogLine logLine)
        {
            if (CurrentClientRun == null)
             {
            Add(new ClientRun(logLine.LineIndex));
             }

             Debug.Assert(CurrentClientRun != null);

             // If we've already seen a WorkUnitRunning line, ignore this one.);
             if (_currentLineType.Equals(LogLineType.WorkUnitRunning)) return;

             // Not Checking the Queue Slot - we don't care if we found a valid slot or not
             if (_unitIndexData.ProcessingIndex > -1)
             {
            CurrentClientRun.UnitIndexes.Add(new UnitIndex(_unitIndexData.QueueSlotIndex, _unitIndexData.ProcessingIndex));
             }
             else if (_unitIndexData.WorkingIndex > -1)
             {
            CurrentClientRun.UnitIndexes.Add(new UnitIndex(_unitIndexData.QueueSlotIndex, _unitIndexData.WorkingIndex));
             }
             else if (_unitIndexData.StartIndex > -1)
             {
            CurrentClientRun.UnitIndexes.Add(new UnitIndex(_unitIndexData.QueueSlotIndex, _unitIndexData.StartIndex));
             }
             else
             {
            CurrentClientRun.UnitIndexes.Add(new UnitIndex(_unitIndexData.QueueSlotIndex, logLine.LineIndex));
             }

             _currentLineType = logLine.LineType;

             // Re-initialize Values
             _unitIndexData.Initialize();
        }
Exemplo n.º 21
0
        protected override void HandleWorkUnitProcessing(LogLine logLine)
        {
            base.HandleWorkUnitProcessing(logLine);

             // If we have not found a ProcessingIndex (== -1) then set it.
             // Othwerwise, if ProcessingIndex (!= -1) and a CoreDownloadIndex
             // has been observerd and is greater than the current ProcessingIndex,
             // then update the ProcessingIndex to bypass the CoreDownload section
             // of the log file.
             if (_unitIndexData.ProcessingIndex == -1 ||
            (_unitIndexData.ProcessingIndex != -1 &&
             _unitIndexData.CoreDownloadIndex > _unitIndexData.ProcessingIndex))
             {
            _unitIndexData.ProcessingIndex = logLine.LineIndex;
             }

             _currentLineType = logLine.LineType;
        }
Exemplo n.º 22
0
        protected override void HandleWorkUnitPaused(LogLine logLine)
        {
            base.HandleWorkUnitPaused(logLine);

             _currentLineType = logLine.LineType;
        }
Exemplo n.º 23
0
 private void HandleWorkUnitCoreDownload(LogLine logLine)
 {
     _unitIndexData.CoreDownloadIndex = logLine.Index;
     _currentLineType = logLine.LineType;
 }
Exemplo n.º 24
0
        protected override void HandleWorkUnitCoreDownload(LogLine logLine)
        {
            base.HandleWorkUnitCoreDownload(logLine);

             _unitIndexData.CoreDownloadIndex = logLine.LineIndex;
             _currentLineType = logLine.LineType;
        }
Exemplo n.º 25
0
        protected override void HandleLogHeader(LogLine logLine)
        {
            base.HandleLogHeader(logLine);

             // If the last line observed was a LogOpen or a LogHeader, return
             // and don't use this as a signal to add a new ClientRun.
             if (_currentLineType.Equals(LogLineType.LogOpen) ||
             _currentLineType.Equals(LogLineType.LogHeader)) return;

             // Otherwise, if we see a LogHeader and the preceeding line was not
             // a LogOpen or a LogHeader, then we use this as a signal to create
             // a new ClientRun.  This is a backup option and I don't expect this
             // situtation to happen at all if the log file is not corrupt.
             Add(new ClientRun(logLine.LineIndex));

             _currentLineType = logLine.LineType;
        }
Exemplo n.º 26
0
 private void HandleWorkUnitPaused(LogLine logLine)
 {
     _currentLineType = logLine.LineType;
 }
Exemplo n.º 27
0
        private static string ReadOutputLogText(LogLineType type, string applicationName, DateTime timestamp)
        {
            string result = null;

            XmlNode[] nodes = ReadOutputLogXml(type, applicationName, timestamp);
            if (nodes != null)
            {
                result = "";

                foreach (XmlNode lineNode in nodes)
                {
                    string t = Attributes.Get(lineNode, "timestamp");
                    if (t != null)
                    {
                        DateTime date = DateTime.MinValue;
                        if (DateTime.TryParse(t, out date))
                        {
                            if (date > timestamp)
                            {
                                result += lineNode.InnerText + Environment.NewLine;
                            }
                        }
                    }
                }
            }

            return result;
        }
Exemplo n.º 28
0
 public LogEventArgs(LogLineType eventType, string logString)
 {
     EventType = eventType;
     LogString = logString;
 }
Exemplo n.º 29
0
 public LogEventArgs(LogLineType eventType, Exception ex)
     : this(eventType, ex.StackTrace)
 {
 }
Exemplo n.º 30
0
 private void HandleLogOpen(LogLine logLine)
 {
     EnsureSlotRunExists(logLine.Index, FoldingSlot, true);
     _currentLineType = logLine.LineType;
 }
Exemplo n.º 31
0
        private void ReadChanged(LogLineType type)
        {
            switch (type)
            {
                case LogLineType.Debug:

                    if (debugDelayTimer != null) debugDelayTimer.Enabled = false;

                    debugDelayTimer = new System.Timers.Timer();
                    debugDelayTimer.Interval = READ_DELAY;
                    debugDelayTimer.Elapsed += DebugDelayTimer_Elapsed;
                    debugDelayTimer.Enabled = true;
                    break;

                case LogLineType.Error:

                    if (errorDelayTimer != null) errorDelayTimer.Enabled = false;

                    errorDelayTimer = new System.Timers.Timer();
                    errorDelayTimer.Interval = READ_DELAY;
                    errorDelayTimer.Elapsed += ErrorDelayTimer_Elapsed;
                    errorDelayTimer.Enabled = true;
                    break;

                case LogLineType.Notification:

                    if (notificationDelayTimer != null) notificationDelayTimer.Stop();
                    else
                    {
                        notificationDelayTimer = new System.Timers.Timer();
                        notificationDelayTimer.Interval = READ_DELAY;
                        notificationDelayTimer.Elapsed += NotificationDelayTimer_Elapsed;
                    }

                    notificationDelayTimer.Start();

                    break;

                case LogLineType.Warning:

                    if (warningDelayTimer != null) warningDelayTimer.Enabled = false;

                    warningDelayTimer = new System.Timers.Timer();
                    warningDelayTimer.Interval = READ_DELAY;
                    warningDelayTimer.Elapsed += WarningDelayTimer_Elapsed;
                    warningDelayTimer.Enabled = true;
                    break;
            }
        }
Exemplo n.º 32
0
        private void ReadLog(LogLineType type)
        {
            DateTime time = DateTime.MinValue;

            switch (type)
            {
                case LogLineType.Debug: time = lastDebugTimestamp; break;
                case LogLineType.Error: time = lastErrorTimestamp; break;
                case LogLineType.Notification: time = lastNotificationTimestamp; break;
                case LogLineType.Warning: time = lastWarningTimestamp; break;
            }

            var nodes = Logger.ReadOutputLogXml(type, AppicationName, time);
            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    var line = Line.FromXmlNode(node);

                    switch (type)
                    {
                        case LogLineType.Debug: lastDebugTimestamp = line.Timestamp; break;
                        case LogLineType.Error: time = lastErrorTimestamp = line.Timestamp; break;
                        case LogLineType.Notification: time = lastNotificationTimestamp = line.Timestamp; break;
                        case LogLineType.Warning: time = lastWarningTimestamp = line.Timestamp; break;
                    }

                    line.Type = type;
                    LineAdded?.Invoke(line);
                }
            }
        }
Exemplo n.º 33
0
 protected override void HandleWorkUnitWorking(LogLine logLine)
 {
     // This first check allows us to overlook the "+ Working ..." message
      // that gets written after a client is Paused.  We don't want to key
      // work unit positions based on this log entry.
      if (_currentLineType.Equals(LogLineType.WorkUnitPaused))
      {
     // Return to a Running state
     _currentLineType = LogLineType.WorkUnitRunning;
      }
      else
      {
     _unitIndexData.WorkingIndex = logLine.LineIndex;
     _currentLineType = logLine.LineType;
      }
 }
Exemplo n.º 34
0
 public ClientRunListLegacy()
 {
     _currentLineType = LogLineType.Unknown;
 }
Exemplo n.º 35
0
 /// <summary>
 /// Create a new instance of the LogLine.
 /// </summary>
 /// <param name="t">The type of the log.</param>
 /// <param name="content">The content of the log.</param>
 public LogLine(LogLineType t, string content) : base()
 {
     LogType   = t;
     TimeStamp = DateTime.Now;
     Content   = content;
 }
Exemplo n.º 36
0
        protected override void HandleLogOpen(LogLine logLine)
        {
            base.HandleLogOpen(logLine);

             _currentLineType = logLine.LineType;
        }
Exemplo n.º 37
0
        private void ReadChanged(LogLineType type)
        {
            switch (type)
            {
            case LogLineType.Debug:

                if (debugDelayTimer != null)
                {
                    debugDelayTimer.Enabled = false;
                }

                debugDelayTimer          = new System.Timers.Timer();
                debugDelayTimer.Interval = READ_DELAY;
                debugDelayTimer.Elapsed += DebugDelayTimer_Elapsed;
                debugDelayTimer.Enabled  = true;
                break;

            case LogLineType.Error:

                if (errorDelayTimer != null)
                {
                    errorDelayTimer.Enabled = false;
                }

                errorDelayTimer          = new System.Timers.Timer();
                errorDelayTimer.Interval = READ_DELAY;
                errorDelayTimer.Elapsed += ErrorDelayTimer_Elapsed;
                errorDelayTimer.Enabled  = true;
                break;

            case LogLineType.Notification:

                if (notificationDelayTimer != null)
                {
                    notificationDelayTimer.Stop();
                }
                else
                {
                    notificationDelayTimer          = new System.Timers.Timer();
                    notificationDelayTimer.Interval = READ_DELAY;
                    notificationDelayTimer.Elapsed += NotificationDelayTimer_Elapsed;
                }

                notificationDelayTimer.Start();

                break;

            case LogLineType.Warning:

                if (warningDelayTimer != null)
                {
                    warningDelayTimer.Enabled = false;
                }

                warningDelayTimer          = new System.Timers.Timer();
                warningDelayTimer.Interval = READ_DELAY;
                warningDelayTimer.Elapsed += WarningDelayTimer_Elapsed;
                warningDelayTimer.Enabled  = true;
                break;
            }
        }
Exemplo n.º 38
0
        private void ProcessQueue(LogLineType type)
        {
            var lines = queue.FindAll(x => x.Type == type);
            if (lines != null && lines.Count > 0)
            {
                try
                {
                    if (!Directory.Exists(Logger.OutputLogPath)) Directory.CreateDirectory(Logger.OutputLogPath);

                    string filename = "Log-" + Logger.FormatDate(DateTime.Now) + ".log";

                    string path = null;

                    switch (type)
                    {
                        case LogLineType.Debug: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_DEBUG, filename); break;
                        case LogLineType.Error: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_ERROR, filename); break;
                        case LogLineType.Notification: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_NOTIFICATION, filename); break;
                        case LogLineType.Warning: path = Path.Combine(Logger.OutputLogPath, Logger.OUTPUT_DIRECTORY_WARNING, filename); break;
                    }

                    // Write to Log File
                    using (var stream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Write))
                    {
                        using (var writer = new StreamWriter(stream))
                        {
                            foreach (Line line in lines)
                            {
                                writer.WriteLine(line);
                            }
                        }
                    }
                }
                catch (Exception ex) { Console.WriteLine("ProcessQueue(LogLineType) :: Exception :: " + type.ToString() + " :: " + ex.Message); }
            }
        }
Exemplo n.º 39
0
        public static XmlNode[] ReadOutputLogXml(LogLineType type, string applicationName, DateTime timestamp)
        {
            XmlNode[] result = null;

            string logDir = null;

            switch (type)
            {
            case LogLineType.Debug: logDir = OUTPUT_DIRECTORY_DEBUG; break;

            case LogLineType.Error: logDir = OUTPUT_DIRECTORY_ERROR; break;

            case LogLineType.Notification: logDir = OUTPUT_DIRECTORY_NOTIFICATION; break;

            case LogLineType.Warning: logDir = OUTPUT_DIRECTORY_WARNING; break;
            }

            if (!string.IsNullOrEmpty(logDir))
            {
                // Create filename based on current DateTime
                string filename = "Log-" + FormatDate(DateTime.Now) + ".xml";

                // Create full filepath
                string path = Path.Combine(OutputLogPath, logDir, filename);

                // Create temp file to read from (to help prevent file corruption when Logger is writing to the file)
                string tmpFileName = Path.ChangeExtension(Guid.NewGuid().ToString(), ".tmp");
                string tmpPath     = Path.Combine(OutputLogPath, logDir, tmpFileName);

                if (File.Exists(path))
                {
                    File.Copy(path, tmpPath);

                    var doc = Files.ReadDocument(tmpPath);
                    if (doc != null)
                    {
                        if (doc.DocumentElement != null)
                        {
                            var node = doc.DocumentElement.SelectSingleNode("//" + applicationName);
                            if (node != null)
                            {
                                var nodes = new List <XmlNode>();

                                foreach (XmlNode lineNode in node.ChildNodes)
                                {
                                    string t = Attributes.Get(lineNode, "timestamp");
                                    if (t != null)
                                    {
                                        DateTime date = DateTime.MinValue;
                                        if (DateTime.TryParse(t, out date))
                                        {
                                            if (date > timestamp)
                                            {
                                                nodes.Add(lineNode);
                                            }
                                        }
                                    }
                                }

                                result = nodes.ToArray();
                            }
                        }
                    }

                    if (File.Exists(tmpPath))
                    {
                        File.Delete(tmpPath);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 40
0
        public static XmlNode[] ReadOutputLogXml(LogLineType type, string applicationName, DateTime timestamp)
        {
            XmlNode[] result = null;

            string logDir = null;

            switch (type)
            {
                case LogLineType.Debug: logDir = OUTPUT_DIRECTORY_DEBUG; break;
                case LogLineType.Error: logDir = OUTPUT_DIRECTORY_ERROR; break;
                case LogLineType.Notification: logDir = OUTPUT_DIRECTORY_NOTIFICATION; break;
                case LogLineType.Warning: logDir = OUTPUT_DIRECTORY_WARNING; break;
            }

            if (!string.IsNullOrEmpty(logDir))
            {
                // Create filename based on current DateTime
                string filename = "Log-" + FormatDate(DateTime.Now) + ".xml";

                // Create full filepath
                string path = Path.Combine(OutputLogPath, logDir, filename);

                // Create temp file to read from (to help prevent file corruption when Logger is writing to the file)
                string tmpFileName = Path.ChangeExtension(Guid.NewGuid().ToString(), ".tmp");
                string tmpPath = Path.Combine(OutputLogPath, logDir, tmpFileName);

                if (File.Exists(path))
                {
                    File.Copy(path, tmpPath);

                    var doc = Files.ReadDocument(tmpPath);
                    if (doc != null)
                    {
                        if (doc.DocumentElement != null)
                        {
                            var node = doc.DocumentElement.SelectSingleNode("//" + applicationName);
                            if (node != null)
                            {
                                var nodes = new List<XmlNode>();

                                foreach (XmlNode lineNode in node.ChildNodes)
                                {
                                    string t = Attributes.Get(lineNode, "timestamp");
                                    if (t != null)
                                    {
                                        DateTime date = DateTime.MinValue;
                                        if (DateTime.TryParse(t, out date))
                                        {
                                            if (date > timestamp)
                                            {
                                                nodes.Add(lineNode);
                                            }
                                        }
                                    }
                                }

                                result = nodes.ToArray();
                            }
                        }
                    }

                    if (File.Exists(tmpPath)) File.Delete(tmpPath);
                }
            }

            return result;
        }
Exemplo n.º 41
0
        protected override void HandleWorkUnitCoreShutdown(LogLine logLine)
        {
            if (_currentLineType.Equals(LogLineType.WorkUnitRunning))
             {
            AddWorkUnitResult((WorkUnitResult)logLine.LineData);
             }

             _currentLineType = logLine.LineType;
        }
Exemplo n.º 42
0
 public LogEventArgs(LogLineType eventType, Exception ex)
     : this(eventType, string.Format("{0} {1}", ex.Message, ex.StackTrace))
 {
 }
Exemplo n.º 43
0
 private void HandleWorkUnitCoreStart(LogLine logLine)
 {
     _unitIndexData.StartIndex = logLine.Index;
     _currentLineType          = logLine.LineType;
 }