public bool Fill(ModelStateDictionary modelState, bool isPostBack)
{
bool success = true;
if (File.Exists(this.LogPath))
{
IList<string> tail = Tail.Read(this.LogPath, 100).ToList();
IList<string> multiLine = new List<string>();
IList<string> result = new List<string>();
foreach (string line in tail)
{
if (!string.IsNullOrEmpty(line))
{
if (Regex.IsMatch(line, @"^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.[^\s]+"))
{
if (multiLine.Count > 0)
{
multiLine.Add(line.Trim());
result.Add(string.Join("\n", multiLine.Reverse().ToArray()));
multiLine.Clear();
}
else
{
result.Add(line.Trim());
}
}
else
{
multiLine.Add(line.Trim());
}
}
}
this.entries = result
.Select(l => LogEntry.Parse(l))
.ToList();
}
else
{
modelState.AddModelError(string.Empty, string.Format(CultureInfo.InvariantCulture, "There was no log file found at '{0}'.", this.LogPath));
modelState.AddModelError(string.Empty, "Note that no log file will be created if running from the console application (Collar.exe), or the service application. Logs are maintained in those situations under the appropriate Console.exe directory instead.");
success = false;
}
return success;
}