Exemplo n.º 1
0
        public void read_should_return_empty_list_when_file_is_empty()
        {
            // Arrange
            var container = CreateContainer("ExampleLogs/empty.log");
            var repository = new RepositoryMock();
            var logFileParser = new DefaultNLogFormatParser(repository, false);

            // Act
            logFileParser.ParseAndSave(container);
            IEnumerable<LogEntry> list = repository.LogEntries;

            // Assert
            Assert.That(list, Is.Not.Null);
            Assert.That(list.Count(), Is.EqualTo(0));
        }
Exemplo n.º 2
0
        public void read_should_parse_last_exception_type_and_message_from_entry_stack()
        {
            // Arrange
            var container = CreateContainer("ExampleLogs/full.log");
            var repository = new RepositoryMock();
            var logFileParser = new DefaultNLogFormatParser(repository, false);

            // Act
            logFileParser.ParseAndSave(container);
            List<LogEntry> list = repository.LogEntries;

            // Assert
            var entry = list[1];
            Assert.That(entry.DateTime, Is.GreaterThan(DateTime.MinValue));
            Assert.That(entry.ExceptionType, Is.EqualTo("System.NeedSleepException"));
            Assert.That(entry.ExceptionMessage, Is.EqualTo("I can't get no sleep sleep sleep."));
        }
Exemplo n.º 3
0
        public void read_should_parse_all_entries()
        {
            // Arrange
            var container = CreateContainer("ExampleLogs/full.log");
            var repository = new RepositoryMock();
            DateTime expectedDate = DateTime.Parse("2015-09-24 10:25:13.7780");
            var logFileParser = new DefaultNLogFormatParser(repository, false);

            // Act
            logFileParser.ParseAndSave(container);
            IEnumerable<LogEntry> list = repository.LogEntries;

            // Assert
            Assert.That(list, Is.Not.Null);
            Assert.That(list.Count(), Is.EqualTo(648));

            var entry = list.FirstOrDefault();
            Assert.That(entry.DateTime, Is.EqualTo(expectedDate));
            Assert.That(entry.ApplicationName, Is.EqualTo(APP_NAME));
            Assert.That(entry.Server, Is.EqualTo(container.Server.Name));
            Assert.That(entry.Environment, Is.EqualTo(container.Environment.Name));
            Assert.That(entry.Source, Is.EqualTo("AmazingApp"));
            Assert.That(entry.Message, Is.EqualTo("A non critical error occured on Page:http://www.example.com/Places/To/Buy/Caravans/WestLondon.html\r\n"));
        }
Exemplo n.º 4
0
        public void Run(string[] args)
        {
            var options = new Options();
            bool success = CommandLine.Parser.Default.ParseArguments(args, options);

            if (success)
            {
                // Nothing to do
                if (!options.Import && !options.CopyFiles && !options.WipeData && !options.Index)
                {
                    System.Console.WriteLine(options.GetUsage());
                    return;
                }

                if (options.WipeData)
                {
                    System.Console.WriteLine("Wiping the database.");
                    _repository.DeleteAll();
                }

                var logReader = new FileSystemLogReader(_configuration);
                var containerList = new List<ServerLogFileContainer>();

                // Populate the list of files to copy/import first.
                if (options.CopyFiles || options.Import)
                {
                    if (!string.IsNullOrEmpty(options.Environment))
                    {
                        System.Console.WriteLine("- Restricting import to {0} environment only", options.Environment);
                        containerList = logReader.ScanSingleEnvironment(options.Environment).ToList();
                    }
                    else if (!string.IsNullOrEmpty(options.Server))
                    {
                        System.Console.WriteLine("- Restricting import to {0} server only", options.Server);
                        containerList.Add(logReader.ScanSingleServer(options.Server));
                    }
                    else
                    {
                        System.Console.WriteLine("- Importing from all environments and servers");
                        containerList = logReader.ScanAllEnvironments().ToList();
                    }
                }

                if (options.CopyFiles)
                {
                    foreach (ServerLogFileContainer container in containerList)
                    {
                        logReader.CopyToLocalDisk(container);
                    }
                }

                if (options.Import)
                {
                    var parser = new DefaultNLogFormatParser(_repository, options.SmartUpdate);

                    if (_configuration.ImportBufferSize > 0)
                        parser.MaxEntriesBeforeSave = _configuration.ImportBufferSize;

                    foreach (ServerLogFileContainer container in containerList)
                    {
                        parser.ParseAndSave(container);
                    }
                }

                if (options.Index)
                {
                    var searchRepository = new SearchRepository(_configuration);
                    searchRepository.CreateIndex(_repository);
                }

                System.Console.WriteLine("Finished.");
            }
        }