Improved logging futher and updated some methods to use LogDebugInformation and to handle exceptions

This commit is contained in:
2026-01-25 08:58:46 -07:00
parent 4fc8b4799d
commit 82441d5247
4 changed files with 47 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<AssemblyVersion>0.0.0.9</AssemblyVersion>
<AssemblyVersion>0.0.0.10</AssemblyVersion>
</PropertyGroup>
</Project>

View File

@@ -17,6 +17,8 @@ public class MovieHelper(ILogger logger)
public bool IsMovieStale(BaseItem movie)
{
ArgumentNullException.ThrowIfNull(movie, "IsMovieStale process recieved a null movie. Logic failure. Exception thrown.");
_loggingHelper.LogDebugInformation("Start of scanning for movie: {Movie}", movie);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
@@ -47,13 +49,20 @@ public class MovieHelper(ILogger logger)
movieIsStale = true;
}
}
else if (createdOutsideCutoff)
if (createdOutsideCutoff && !hasUserData)
{
_loggingHelper.LogDebugInformation("Movie has no user data and was created outside of cutoff: {DateCreated}.", movie.DateCreated);
_loggingHelper.LogDebugInformation("Adding {Movie} to stale movies.", movie);
movieIsStale = true;
}
if (!createdOutsideCutoff && !hasUserData)
{
_loggingHelper.LogDebugInformation("Movie has no user data and was not created outside of cutoff: {DateCreated}.", movie.DateCreated);
_loggingHelper.LogDebugInformation("Movie is not stale.");
}
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("End of scanning for movie: {Movie}", movie);

View File

@@ -69,10 +69,7 @@ public class SeriesHelper(ILogger logger)
public bool IsSeasonDataStale(IReadOnlyList<BaseItem> episodes)
{
if(episodes == null)
{
ArgumentNullException.ThrowIfNull(episodes);
}
ArgumentNullException.ThrowIfNull(episodes, "IsSeasonDataStale process recieved null episodes. Logic failure. Exception thrown.");
bool seasonIsStale = false;

View File

@@ -74,7 +74,7 @@ public sealed class StaleMediaTask : IScheduledTask
List<BaseItem> allItems = [.. _libraryManager.GetItemsResult(query).Items];
_loggingHelper.LogInformation("Total items: {ItemCount}", allItems.Count);
_loggingHelper.LogInformation("Stale items found: {AllItems}", allItems);
_loggingHelper.LogDebugInformation("Items found: {AllItems}", allItems);
List<BaseItem> series = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Series)];
List<BaseItem> movies = [.. allItems.Where(item => item.GetBaseItemKind() == BaseItemKind.Movie)];
@@ -85,6 +85,7 @@ public sealed class StaleMediaTask : IScheduledTask
List<BaseItem> staleSeasons = [.. series.SelectMany(GetStaleSeasons)];
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Starting scan of movies items.");
_loggingHelper.LogInformation("-------------------------------------------------");
@@ -93,26 +94,34 @@ public sealed class StaleMediaTask : IScheduledTask
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Stale Movies found: {StaleMovies}", staleMovies.Count);
if (staleMovies.Count > 0 && Configuration.DebugMode)
if (staleMovies.Count > 0)
{
foreach (var movieInfo in staleMovies)
{
_loggingHelper.LogDebugInformation("Movie Info: ID: {Id} | Movie Name: {MovieName}", [movieInfo.Id, movieInfo.Name]);
_loggingHelper.LogInformation("Movie Info: ID: {Id} | Movie Name: {MovieName}", [movieInfo.Id, movieInfo.Name]);
}
}
else
{
_loggingHelper.LogInformation("No stale movies found!");
}
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Stale seasons found: {StaleSeasons}", staleSeasons.Count);
if (staleSeasons.Count > 0 && Configuration.DebugMode)
if (staleSeasons.Count > 0)
{
IEnumerable<SeriesInfo> staleSeriesInfo = FindSeriesInfo(staleSeasons);
foreach (var seriesInfo in staleSeriesInfo)
{
_loggingHelper.LogDebugInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
_loggingHelper.LogInformation("Series Info: ID: {Id} | Series Name: {SeriesName} | Stale Seasons: {Seasons}", [seriesInfo.Id, seriesInfo.SeriesName, string.Join(", ", seriesInfo.Seasons)]);
}
}
else
{
_loggingHelper.LogInformation("No stale seasons found!");
}
_loggingHelper.LogInformation("-------------------------------------------------");
_loggingHelper.LogInformation("Ending stale media scan...");
@@ -125,7 +134,15 @@ public sealed class StaleMediaTask : IScheduledTask
{
List<BaseItem> staleMovies = [];
staleMovies.AddRange(movies.Where(_movieHelper.IsMovieStale));
try
{
staleMovies.AddRange(movies.Where(_movieHelper.IsMovieStale));
}
catch (ArgumentNullException ex)
{
_loggingHelper.LogInformation("Arguement Null Exception in GetStaleMovies!");
_loggingHelper.LogInformation(ex.Message);
}
return staleMovies;
}
@@ -136,7 +153,6 @@ public sealed class StaleMediaTask : IScheduledTask
_loggingHelper.LogDebugInformation("Debug data for series: {SeriesName}", item.Name);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
// Gets each season in a show
var seasons = _libraryManager.GetItemList(new InternalItemsQuery
{
ParentId = item.Id,
@@ -153,7 +169,17 @@ public sealed class StaleMediaTask : IScheduledTask
_loggingHelper.LogDebugInformation("Season debug information for {SeasonNumber}:", season);
bool isSeasonDataStale = _seriesHelper.IsSeasonDataStale(episodes);
bool isSeasonDataStale = false;
try
{
isSeasonDataStale = _seriesHelper.IsSeasonDataStale(episodes);
}
catch (ArgumentNullException ex)
{
_loggingHelper.LogInformation("Arguement Null Exception in GetStaleSeasons!");
_loggingHelper.LogInformation(ex.Message);
}
_loggingHelper.LogDebugInformation("End of season debug information for {SeasonNumber}.", season);
@@ -163,7 +189,6 @@ public sealed class StaleMediaTask : IScheduledTask
_loggingHelper.LogDebugInformation("-------------------------------------------------");
_loggingHelper.LogDebugInformation("End of scanning for series: {Series}", item);
_loggingHelper.LogDebugInformation("-------------------------------------------------");
return staleSeasons;
}
@@ -193,6 +218,7 @@ public sealed class StaleMediaTask : IScheduledTask
IEnumerable<TaskTriggerInfo> IScheduledTask.GetDefaultTriggers()
{
// Run this task every 24 hours
// Unnecessary, and will be removed once front end page is ready.
yield return new TaskTriggerInfo
{
Type = TaskTriggerInfoType.IntervalTrigger,