Exemple #1
0
 private static IDictionary <string, string> MapLogItemToTableEntity(SitecoreLogEntry logItem, DiagnosticsSourceSummary source, string partitionKey, string fileName)
 {
     return(new Dictionary <string, string> {
         { SitecoreLogFields.Timestamp, logItem.LogDateTime.ToString("s") },
         { SitecoreLogFields.PartitionKey, partitionKey },
         { SitecoreLogFields.RowKey, $"{fileName}_{logItem.LogLineNumber}" },
         { SitecoreLogFields.CbType, source.TypeName },
         { SitecoreLogFields.Level, logItem.Level },
         { SitecoreLogFields.ProcessId, logItem.EventSource },
         { SitecoreLogFields.Message, logItem.Message }
     });
 }
Exemple #2
0
        private static DynamicTableEntity MapLogItemToTableEntity(SitecoreLogEntry logItem, string partitionKey,
                                                                  string fileName)
        {
            var entity = new DynamicTableEntity
            {
                Timestamp    = new DateTimeOffset(logItem.LogDateTime),
                PartitionKey = partitionKey,
                RowKey       = string.Format("{0}_{1}", fileName, logItem.LogLineNumber)
            };

            entity.Properties.Add(SitecoreLogFields.Level, new EntityProperty(logItem.Level));
            entity.Properties.Add(SitecoreLogFields.ProcessId, new EntityProperty(logItem.EventSource));
            entity.Properties.Add(SitecoreLogFields.Message, new EntityProperty(logItem.Message));
            return(entity);
        }
Exemple #3
0
        public IEnumerable <DynamicTableEntity> Parse(Stream body, Uri id, long position = 0, long endPosition = 0)
        {
            if (body.Position != 0)
            {
                body.Position = 0;
            }

            if (endPosition == 0)
            {
                endPosition = long.MaxValue;
            }

            string line;
            var    lineNumber = 0;
            var    fileName   = GetFileName(id);

            var idSegments = id.Segments.Skip(2).Select(x => x.Replace("/", "")).ToArray();
            var partionKey = string.Join("_", idSegments.Take(idSegments.Length - 1));
            var fileDate   = GetFileDate(fileName);

            var logLineParser = new SitecoreLogLineParser();

            SitecoreLogEntry currentEntry = null;
            var reader = new StreamReader(body);

            while (body.Position < endPosition && (line = reader.ReadLine()) != null)
            {
                lineNumber++;

                if (body.Position < position)
                {
                    continue;
                }

                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                //remove connection string passwords in exceptions etc (thanks sitecore)
                line = ReplaceSecureInformation(line, "password="******"**PASSWORD**REDACTED**");
                line = ReplaceSecureInformation(line, "user id=", "**USER**REDACTED**");

                var logItem = logLineParser.ParseLine(line, fileDate);
                if (logItem != null)
                {
                    var logText = logItem.Message;
                    //filter out rubbish logs. eg blank INFO during sitecore startup
                    if (string.IsNullOrWhiteSpace(logText) || logText.StartsWith("*****"))
                    {
                        continue;
                    }

                    logItem.LogLineNumber = lineNumber;
                }

                if (logItem == null && currentEntry != null)
                {
                    // Existing multiline message
                    currentEntry.AppendMessageText(line);
                }
                else if (logItem != null && currentEntry == null)
                {
                    // new entry found
                    currentEntry = logItem;
                }
                else if (currentEntry != null)
                {
                    //new entry found, current one is completed.
                    yield return(MapLogItemToTableEntity(currentEntry, partionKey, fileName));

                    currentEntry = logItem;
                }
            }

            if (currentEntry != null)
            {
                yield return(MapLogItemToTableEntity(currentEntry, partionKey, fileName));
            }
        }