BlueCollar.Examples.Webpages._Default.OnLoad C# (CSharp) Method

OnLoad() protected method

Raises the page's Load event.
protected OnLoad ( EventArgs e ) : void
e System.EventArgs The event arguments.
return void
        protected override void OnLoad(EventArgs e)
        {
            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
            {
                this.Errors.Add(string.Format(CultureInfo.InvariantCulture, "There was no log file found at '{0}'.", this.LogPath));
                this.Errors.Add("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.");
            }

            base.OnLoad(e);
        }