Skip to content

Commit

Permalink
Reduce monitor logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ptr727 committed May 24, 2023
1 parent f5ccb3c commit c043f1f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
12 changes: 6 additions & 6 deletions PlexCleaner/Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static void OnChanged(FileSystemEventArgs e, Monitor monitor)

private void OnChangedEx(FileSystemEventArgs e)
{
Log.Logger.Information("OnChanged : {ChangeType} : {FullPath}", e.ChangeType, e.FullPath);
Log.Logger.Verbose("OnChanged : {ChangeType} : {FullPath}", e.ChangeType, e.FullPath);
switch (e.ChangeType)
{
case WatcherChangeTypes.Changed:
Expand Down Expand Up @@ -169,7 +169,7 @@ private static void OnRenamed(RenamedEventArgs e, Monitor monitor)

private void OnRenamedEx(RenamedEventArgs e)
{
Log.Logger.Information("OnRenamed : {ChangeType} : {OldFullPath} to {FullPath}", e.ChangeType, e.OldFullPath, e.FullPath);
Log.Logger.Verbose("OnRenamed : {ChangeType} : {OldFullPath} to {FullPath}", e.ChangeType, e.OldFullPath, e.FullPath);
switch (e.ChangeType)
{
case WatcherChangeTypes.Renamed:
Expand Down Expand Up @@ -213,8 +213,8 @@ private void OnChanged(string pathname)
// Get the file details
FileInfo fileInfo = new(pathname);

// Ignore our own sidecar and *.tmp, *.tmpint, *.tmprmx files being created
if (!fileInfo.Extension.StartsWith(".tmp", StringComparison.OrdinalIgnoreCase) &&
// Ignore sidecar and temp files
if (!ProcessFile.IsTempFile(fileInfo) &&
!SidecarFile.IsSidecarFile(fileInfo))
{
folderName = fileInfo.DirectoryName;
Expand All @@ -239,13 +239,13 @@ private void OnChanged(string pathname)
if (WatchFolders.ContainsKey(folderName))
{
// Update the modified time
Log.Logger.Information("Updating folder for processing by {MonitorWaitTime} : {Folder}", DateTime.Now.AddSeconds(Program.Config.MonitorOptions.MonitorWaitTime), folderName);
Log.Logger.Verbose("Updating timestamp for folder in queue : {Folder}", folderName);
WatchFolders[folderName] = DateTime.UtcNow;
}
else
{
// Add the folder
Log.Logger.Information("Adding folder for processing by {MonitorWaitTime} : {Folder}", DateTime.Now.AddSeconds(Program.Config.MonitorOptions.MonitorWaitTime), folderName);
Log.Logger.Information("Adding folder to processing queue : {Folder}", folderName);
WatchFolders.Add(folderName, DateTime.UtcNow);
}
}
Expand Down
6 changes: 6 additions & 0 deletions PlexCleaner/ProcessFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,12 @@ static AudioInfo FindPreferredAudio(IEnumerable<TrackInfo> trackInfoList)
return audioInfoList.First();
}

public static bool IsTempFile(FileInfo fileInfo)
{
// *.tmp, *.tmpint, *.tmprmx
return fileInfo.Extension.StartsWith(".tmp", StringComparison.OrdinalIgnoreCase);
}

public MediaInfo FfProbeInfo { get; private set; }
public MediaInfo MkvMergeInfo { get; private set; }
public MediaInfo MediaInfoInfo { get; private set; }
Expand Down
25 changes: 18 additions & 7 deletions PlexCleaner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,32 @@ private static void CreateLogger(string logfile)
// Need to explicitly add thread id formatting to file and console output
loggerConfiguration.Enrich.WithThreadId();

// Default minimum log level
#if DEBUG
LogEventLevel logLevelDefault = LogEventLevel.Debug;
#else
LogEventLevel logLevelDefault = LogEventLevel.Information;
#endif

// Log to console
loggerConfiguration.WriteTo.Console(theme: AnsiConsoleTheme.Code, outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] <{ThreadId}> {Message}{NewLine}{Exception}");
loggerConfiguration.WriteTo.Console(theme: AnsiConsoleTheme.Code,
restrictedToMinimumLevel: logLevelDefault,
outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] <{ThreadId}> {Message}{NewLine}{Exception}");

// Log to file
// outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
// Remove lj to quote strings
if (!string.IsNullOrEmpty(logfile))
{
// Set log level
LogEventLevel logFileMinimumLevel = Options.LogWarning ? LogEventLevel.Warning : LogEventLevel.Information;
if (Options.LogWarning)
{
logLevelDefault = LogEventLevel.Warning;
}

// Write async to file
loggerConfiguration.WriteTo.Async(action => action.File(logfile,
restrictedToMinimumLevel: logFileMinimumLevel,
restrictedToMinimumLevel: logLevelDefault,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] <{ThreadId}> {Message}{NewLine}{Exception}"));
}

Expand Down Expand Up @@ -422,14 +434,13 @@ private static Program Create(CommandLineOptions options, bool verifyTools)
}

// Log app and runtime version
// ReSharper disable once RedundantAssignment
bool debugBuild = false;
#if DEBUG
debugBuild = true;
const bool debugBuild = true;
#else
const bool debugBuild = false;
#endif
string appVersion = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
string runtimeVersion = Environment.Version.ToString();
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
Log.Logger.Information("Application Version : {AppVersion}, Runtime Version : {RuntimeVersion}, Debug Build: {DebugBuild}", appVersion, runtimeVersion, debugBuild);

// Parallel processing config
Expand Down

0 comments on commit c043f1f

Please sign in to comment.