/// <summary> /// Adds a log to the <see cref="Occurrences"/> at the top of the list. /// </summary> /// <param name="log">The log to add to the occurrences.</param> /// <param name="maxLogs">The maximum number of logs to store in this structured log. If exceeded, the oldest log will be removed from this structured log.</param> public void AddLog(Log log, int maxLogs = 20) { if (FirstOccurrence == default) { FirstOccurrence = DateTimeOffset.UtcNow; } Occurrences.Insert(0, log); LastOccurrence = DateTimeOffset.UtcNow; OccurrenceCount++; Level = log.Level; if (string.IsNullOrEmpty(MessageTemplate)) { MessageTemplate = log.Template ?? log.Message ?? string.Empty; } Function = log.Function; File = log.File; LineNumber = log.LineNumber; // We don't store an infinite number of logs inside Occurrences. Trim them down as configured. if (Occurrences.Count > maxLogs) { Occurrences.RemoveAt(Occurrences.Count - 1); } }
/// <summary> /// Adds a log to the <see cref="Occurrences"/> at the top of the list. /// </summary> /// <param name="log">The log to add to the occurrences.</param> public void AddLog(Log log) { if (FirstOccurrence == default(DateTimeOffset)) { FirstOccurrence = DateTimeOffset.UtcNow; } Occurrences.Insert(0, log); LastOccurrence = DateTimeOffset.UtcNow; OccurrenceCount++; Level = log.Level; MessageTemplate = log.Template ?? log.Message ?? string.Empty; Function = log.Function; File = log.File; LineNumber = log.LineNumber; // We don't store an infinite number of logs inside Occurrences. Trim them down as configured. if (Occurrences.Count > RavenStructuredLoggerProvider.MaxStructuredLogOccurrences) { Occurrences.RemoveAt(Occurrences.Count - 1); } }