Ejemplo n.º 1
0
        public void Add(LogEntry logEntry)
        {
            try
            {
                EnsureDirectoryExists();

                StandardAnalyzer analyzer = new StandardAnalyzer(LUCENEVERSION);
                using (IndexWriter writer = new IndexWriter(FSDirectory.Open(new DirectoryInfo(IndexPath)), analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    Document document = CreateDocument(logEntry);

                    writer.AddDocument(document);
                    writer.Optimize();
                }
            }
            catch (Exception ex)
            {
                throw new SearchException(ex, "An error occured while adding entry '{0}' to the search index", logEntry.DateTime);
            }
        }
Ejemplo n.º 2
0
        public ActionResult Search(string applicationName, string q)
        {
            Environment currentEnvironment = GetSelectedEnvironment();

            ViewBag.EnvironmentName = currentEnvironment.Name;
            ViewBag.ApplicationName = applicationName;
            ViewBag.SearchQuery = q;

            IEnumerable<LogEntry> results = new LogEntry[0];

            if (_configuration.IsLuceneEnabled)
            {
                var searchRepository = new SearchRepository(_configuration);
                string query = searchRepository.CreateLuceneSearchSyntax(applicationName, currentEnvironment.Name, q);
                results = searchRepository.Search(query);
            }
            else
            {
                // Use MongoDB's slower search.
                results = _repository.Search(currentEnvironment.Name, applicationName, q);
            }

            return View(results);
        }
Ejemplo n.º 3
0
        private LogEntry ParseLogEntry(string environment, string server, string appName, string contents)
        {
            MatchCollection matches = _entryRegex.Matches(contents);
            LogEntry entry = null;

            if (matches.Count > 0)
            {
                try
                {
                    Match match = matches[0];

                    entry = new LogEntry();
                    entry.Id = Guid.NewGuid();
                    entry.DateTime = DateTime.Parse(match.Groups["date"].Value);
                    entry.Source = match.Groups["source"].Value;
                    entry.Message = contents.Substring((match.Groups["source"].Index + 1) + match.Groups["source"].Length);
                    entry.Level = "Error";
                    entry.Server = server;
                    entry.ApplicationName = appName;
                    entry.Environment = environment;
                    FillExceptionType(entry);
                }
                catch (Exception)
                {
                    // Ignore for now
                }
            }

            return entry;
        }
Ejemplo n.º 4
0
        private void FillExceptionType(LogEntry entry)
        {
            if (string.IsNullOrEmpty(entry.Message))
                return;

            string message = entry.Message;

            int start = message.LastIndexOf("Exception Type: ");
            if (start > -1)
            {
                int end = message.IndexOf(Environment.NewLine, start);
                if (end > -1)
                {
                    int typeStart = start + "Exception Type: ".Length;
                    string exceptionType = message.Substring(typeStart, end - typeStart);
                    entry.ExceptionType = exceptionType;

                    int messageStart = message.IndexOf("Message: ", start);
                    if (messageStart > -1)
                    {
                        int messageEnd = message.IndexOf(Environment.NewLine, messageStart);
                        if (messageEnd > -1)
                        {
                            messageStart = messageStart + "Message: ".Length;
                            string exceptionMessage = message.Substring(messageStart, messageEnd - messageStart);
                            entry.ExceptionMessage = exceptionMessage;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private Document CreateDocument(LogEntry logEntry)
        {
            Document document = new Document();

            document.Add(new Field("id", logEntry.Id.ToString(), Field.Store.YES, Field.Index.NO));
            document.Add(new Field("environment", logEntry.Environment, Field.Store.YES, Field.Index.NOT_ANALYZED));
            document.Add(new Field("server", logEntry.Server, Field.Store.YES, Field.Index.NOT_ANALYZED));
            document.Add(new Field("application", logEntry.ApplicationName, Field.Store.YES, Field.Index.NOT_ANALYZED));
            document.Add(new Field("date", logEntry.DateTime.ToShortDateString(), Field.Store.YES, Field.Index.NO));
            document.Add(new Field("exceptionMessage", logEntry.ExceptionMessage??"", Field.Store.YES, Field.Index.ANALYZED));
            document.Add(new Field("exceptionType", logEntry.ExceptionType ?? "", Field.Store.YES, Field.Index.ANALYZED));
            document.Add(new Field("message", logEntry.Message ?? "", Field.Store.NO, Field.Index.ANALYZED));
            document.Add(new Field("truncatedMessage", logEntry.TruncatedMessage, Field.Store.YES, Field.Index.NO));

            return document;
        }
Ejemplo n.º 6
0
 public virtual void Update(LogEntry logEntry)
 {
     EnsureDirectoryExists();
     Delete(logEntry);
     Add(logEntry);
 }
Ejemplo n.º 7
0
        public int Delete(LogEntry logEntry)
        {
            try
            {
                int count = 0;
                using (IndexReader reader = IndexReader.Open(FSDirectory.Open(new DirectoryInfo(IndexPath)), false))
                {
                    count += reader.DeleteDocuments(new Term("id", logEntry.Id.ToString()));
                }

                return count;
            }
            catch (Exception ex)
            {
                throw new SearchException(ex, "An error occured while deleting entry '{0}' from the search index", logEntry.DateTime);
            }
        }
Ejemplo n.º 8
0
 public void Save(LogEntry entry)
 {
     _collection.InsertOneAsync(entry);
 }
Ejemplo n.º 9
0
 public void Save(LogEntry entry)
 {
     LogEntries.Add(entry);
 }