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)); }
static int EntryToGroupKey(LogEntry entry) { var date = entry.DateTimeUtc.Date; return (date.Year * 100 + date.Month) * 100 + date.Day; }
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++; } }
static string EntryToToken(LogEntry entry) { return entry.DateTimeUtc.ToString("yyyyMMddHHmmssffff"); }