/// <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> /// 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); }
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); }
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(); }
/// <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)); }
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); }
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); }
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); } } } } } } }
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; }
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); } } }
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; }
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); } } }
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); } } } }
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); } } }
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); } } } } } }
protected override void HandleWorkUnitStart(LogLine logLine) { _unitIndexData.StartIndex = logLine.LineIndex; _currentLineType = logLine.LineType; }
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(); }
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; }
protected override void HandleWorkUnitPaused(LogLine logLine) { base.HandleWorkUnitPaused(logLine); _currentLineType = logLine.LineType; }
private void HandleWorkUnitCoreDownload(LogLine logLine) { _unitIndexData.CoreDownloadIndex = logLine.Index; _currentLineType = logLine.LineType; }
protected override void HandleWorkUnitCoreDownload(LogLine logLine) { base.HandleWorkUnitCoreDownload(logLine); _unitIndexData.CoreDownloadIndex = logLine.LineIndex; _currentLineType = logLine.LineType; }
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; }
private void HandleWorkUnitPaused(LogLine logLine) { _currentLineType = logLine.LineType; }
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; }
public LogEventArgs(LogLineType eventType, string logString) { EventType = eventType; LogString = logString; }
public LogEventArgs(LogLineType eventType, Exception ex) : this(eventType, ex.StackTrace) { }
private void HandleLogOpen(LogLine logLine) { EnsureSlotRunExists(logLine.Index, FoldingSlot, true); _currentLineType = logLine.LineType; }
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; } }
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); } } }
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; } }
public ClientRunListLegacy() { _currentLineType = LogLineType.Unknown; }
/// <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; }
protected override void HandleLogOpen(LogLine logLine) { base.HandleLogOpen(logLine); _currentLineType = logLine.LineType; }
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; } }
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); } } }
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); }
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; }
protected override void HandleWorkUnitCoreShutdown(LogLine logLine) { if (_currentLineType.Equals(LogLineType.WorkUnitRunning)) { AddWorkUnitResult((WorkUnitResult)logLine.LineData); } _currentLineType = logLine.LineType; }
public LogEventArgs(LogLineType eventType, Exception ex) : this(eventType, string.Format("{0} {1}", ex.Message, ex.StackTrace)) { }
private void HandleWorkUnitCoreStart(LogLine logLine) { _unitIndexData.StartIndex = logLine.Index; _currentLineType = logLine.LineType; }