Exemplo n.º 1
0
 private static string FormatLogEntry(LogEntry logEntry)
 {
     return string.Format(
         @"
     <log>
       <level>{0}</level>
       <timestamp>{1}</timestamp>
       <message>{2}</message>
       <error>{3}</error>
       <source>{4}</source>
     </log>
     ",
         logEntry.Level,
         logEntry.DateTimeUtc.ToString("o", CultureInfo.InvariantCulture),
         SecurityElement.Escape(logEntry.Message),
         SecurityElement.Escape(logEntry.Error),
         SecurityElement.Escape(logEntry.Source));
 }
Exemplo n.º 2
0
 static int EntryToGroupKey(LogEntry entry)
 {
     var date = entry.DateTimeUtc.Date;
     return (date.Year * 100 + date.Month) * 100 + date.Day;
 }
Exemplo n.º 3
0
        public void Log(LogLevel level, Exception ex, object message)
        {
            if (!IsEnabled(level))
            {
                return;
            }

            var now = DateTime.UtcNow;

            var logEntry = new LogEntry
                {
                    DateTimeUtc = now,
                    Level = level.ToString(),
                    Message = message.ToString(),
                    Error = ex != null ? ex.ToString() : string.Empty,
                    Source = _source ?? string.Empty
                };

            var blobContent = FormatLogEntry(logEntry);
            var blobName = string.Format("{0}/{1}/", FormatDateTimeNamePrefix(logEntry.DateTimeUtc), logEntry.Level);
            var blobContainer = LevelToContainer(level);

            var attempt = 0;
            while (!_blobStorage.PutBlob(blobContainer, blobName + attempt, blobContent, false))
            {
                attempt++;
            }
        }
Exemplo n.º 4
0
 static string EntryToToken(LogEntry entry)
 {
     return entry.DateTimeUtc.ToString("yyyyMMddHHmmssffff");
 }