aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Logging/ApplicationLogFileParser.cs
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2020-06-14 10:10:01 +0300
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2020-06-14 10:10:01 +0300
commit5bf34bdff780c20a60a1999ca5db89fdf23bdbf4 (patch)
tree11671a0b5e845cdb4209c62d452dc0a5df2726ee /Software/Visual_Studio/Tango.Logging/ApplicationLogFileParser.cs
parentd28f4ab232aaec838d80335b98f906fbddc21dca (diff)
downloadTango-5bf34bdff780c20a60a1999ca5db89fdf23bdbf4.tar.gz
Tango-5bf34bdff780c20a60a1999ca5db89fdf23bdbf4.zip
Test if file exists in Log files before a parsing.
Related Work Items: #2985
Diffstat (limited to 'Software/Visual_Studio/Tango.Logging/ApplicationLogFileParser.cs')
-rw-r--r--Software/Visual_Studio/Tango.Logging/ApplicationLogFileParser.cs47
1 files changed, 25 insertions, 22 deletions
diff --git a/Software/Visual_Studio/Tango.Logging/ApplicationLogFileParser.cs b/Software/Visual_Studio/Tango.Logging/ApplicationLogFileParser.cs
index 1530c4d27..6bd53f433 100644
--- a/Software/Visual_Studio/Tango.Logging/ApplicationLogFileParser.cs
+++ b/Software/Visual_Studio/Tango.Logging/ApplicationLogFileParser.cs
@@ -84,32 +84,35 @@ namespace Tango.Logging
private void Parse(string file, DateTime datetime, ref List<LogItemBase> logItems)
{
- String text = File.ReadAllText(file);
- var logs = Regex.Split(text, @"(\[\d{2}:\d{2}:\d{2}.\d{2}\])");
-
- for (int i = 1; i < logs.Length; i += 2)
+ if(File.Exists(file))
{
- try
+ String text = File.ReadAllText(file);
+ var logs = Regex.Split(text, @"(\[\d{2}:\d{2}:\d{2}.\d{2}\])");
+
+ for (int i = 1; i < logs.Length; i += 2)
{
- DateTime date = DateTime.ParseExact(logs[i].Replace("[", "").Replace("]", ""), "HH:mm:ss.ff", CultureInfo.InvariantCulture);
- String rest = logs[i + 1];
-
- var matches = Regex.Matches(rest, @"(?<=\[)(.*?)(?=\])");
+ try
+ {
+ DateTime date = DateTime.ParseExact(logs[i].Replace("[", "").Replace("]", ""), "HH:mm:ss.ff", CultureInfo.InvariantCulture);
+ String rest = logs[i + 1];
- MessageLogItem item = new MessageLogItem();
- item.TimeStamp = new DateTime(datetime.Year, datetime.Month, datetime.Day, date.Hour, date.Minute, date.Second, date.Millisecond);
- item.Category = (LogCategory)Enum.Parse(typeof(LogCategory), matches[0].ToString());
- item.CallerFile = matches[1].ToString();
- item.CallerMethodName = matches[2].ToString();
- item.CallerLineNumber = int.Parse(matches[3].ToString());
+ var matches = Regex.Matches(rest, @"(?<=\[)(.*?)(?=\])");
- int messageStartIndex = matches[3].Index + matches[3].Length + 2;
- item.Message = rest.Substring(messageStartIndex, rest.Length - messageStartIndex);
- logItems.Add(item);
- }
- catch (Exception ex)
- {
- LogManager.Default.Log(ex, "Could not parse log line: " + logs[i]);
+ MessageLogItem item = new MessageLogItem();
+ item.TimeStamp = new DateTime(datetime.Year, datetime.Month, datetime.Day, date.Hour, date.Minute, date.Second, date.Millisecond);
+ item.Category = (LogCategory)Enum.Parse(typeof(LogCategory), matches[0].ToString());
+ item.CallerFile = matches[1].ToString();
+ item.CallerMethodName = matches[2].ToString();
+ item.CallerLineNumber = int.Parse(matches[3].ToString());
+
+ int messageStartIndex = matches[3].Index + matches[3].Length + 2;
+ item.Message = rest.Substring(messageStartIndex, rest.Length - messageStartIndex);
+ logItems.Add(item);
+ }
+ catch (Exception ex)
+ {
+ LogManager.Default.Log(ex, "Could not parse log line: " + logs[i]);
+ }
}
}
}