Skip to content
9 changes: 1 addition & 8 deletions Ical.Net.Tests/Logging.Tests/TestLoggingManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,7 @@ public void DemoForOccurrences()
var logs = mgr.Logs.ToList();
/*
2025-07-31 11:00:53.7022|TRACE|Occurrences|Occurrences:
Start: 01/05/2025 08:30:00 -05:00 US-Eastern Period: PT1H End: 01/05/2025 09:30:00 -05:00 US-Eastern
Start: 01/05/2025 09:30:00 -05:00 US-Eastern Period: PT1H End: 01/05/2025 10:30:00 -05:00 US-Eastern
Start: 01/12/2025 08:30:00 -05:00 US-Eastern Period: PT1H End: 01/12/2025 09:30:00 -05:00 US-Eastern
Start: 01/12/2025 09:30:00 -05:00 US-Eastern Period: PT1H End: 01/12/2025 10:30:00 -05:00 US-Eastern
Start: 01/19/2025 08:30:00 -05:00 US-Eastern Period: PT1H End: 01/19/2025 09:30:00 -05:00 US-Eastern
Start: 01/19/2025 09:30:00 -05:00 US-Eastern Period: PT1H End: 01/19/2025 10:30:00 -05:00 US-Eastern
Start: 01/26/2025 08:30:00 -05:00 US-Eastern Period: PT1H End: 01/26/2025 09:30:00 -05:00 US-Eastern
Start: 01/26/2025 09:30:00 -05:00 US-Eastern Period: PT1H End: 01/26/2025 10:30:00 -05:00 US-Eastern
...
*/
Assert.That(logs, Has.Count.EqualTo(1));
Assert.That(logs[0], Does.Contain("Occurrences"));
Expand Down
16 changes: 10 additions & 6 deletions Ical.Net.Tests/Logging/ToLogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,28 @@ public static string ToLog(this Exception? exception)
public static string ToLog(this IEnumerable<Occurrence>? occurrences)
{
var sb = new StringBuilder();
if (occurrences == null || !occurrences.Any())
var occurrenceList = occurrences?.ToList();
if (occurrenceList == null || occurrenceList.Count == 0)
{
return "No occurrences found.";
}

sb.AppendLine("Occurrences:");
sb.Append(occurrenceList.Count).AppendLine(" occurrences:");

foreach (var occurrence in occurrences)
foreach (var occurrence in occurrenceList)
{
sb.AppendLine(occurrence.ToLog());
}

return sb.ToString();
return sb.ToString().TrimEnd(Environment.NewLine.ToCharArray());
}

public static string ToLog(this Occurrence occurrence)
{
var o = occurrence;
return $"Start: {o.Period.StartTime} Period: {o.Period.Duration?.ToString() ?? "null"} End: {o.Period.EffectiveEndTime ?? o.Period.StartTime.Add(o.Period.Duration!.Value)}";
return $"""
Start: {occurrence.Period.StartTime}
Period: {occurrence.Period.Duration?.ToString() ?? "null"}
End: {occurrence.Period.EffectiveEndTime ?? occurrence.Period.StartTime.Add(occurrence.Period.Duration!.Value)}
""";
}
}
Loading
Loading