Force _IsWindowsService and change log level

This commit is contained in:
Mike Phares 2023-11-16 16:12:10 -07:00
parent 3f7b95c916
commit 58c4b9e487
2 changed files with 6 additions and 2 deletions

View File

@ -7,7 +7,8 @@ internal static partial class HelperEAFLog
internal static bool DeleteFiles(AppSettings appSettings, ILogger<Worker> logger) internal static bool DeleteFiles(AppSettings appSettings, ILogger<Worker> logger)
{ {
IEnumerable<string> files = Directory.EnumerateFiles(appSettings.WatchDirectory, appSettings.EAFLogConfiguration.SearchPattern, SearchOption.AllDirectories); string[] files = Directory.GetFiles(appSettings.WatchDirectory, appSettings.EAFLogConfiguration.SearchPattern, SearchOption.AllDirectories);
logger.LogInformation("After {MillisecondsDelay} with search pattern '{SearchPattern}' found {files}", appSettings.MillisecondsDelay, appSettings.EAFLogConfiguration.SearchPattern, files.Length);
foreach (string file in files) foreach (string file in files)
{ {
if (file.EndsWith(".dll")) if (file.EndsWith(".dll"))
@ -19,7 +20,7 @@ internal static partial class HelperEAFLog
try try
{ File.Delete(file); } { File.Delete(file); }
catch (Exception ex) catch (Exception ex)
{ logger.LogError(ex, "Inner loop error!"); } { logger.LogInformation(ex, "Inner loop error!"); }
} }
return true; return true;
} }

View File

@ -1,5 +1,6 @@
using File_Watcher.Models; using File_Watcher.Models;
using Microsoft.Extensions.Hosting.WindowsServices; using Microsoft.Extensions.Hosting.WindowsServices;
using System.Data;
namespace File_Watcher; namespace File_Watcher;
@ -41,6 +42,8 @@ public partial class Worker : BackgroundService
private async Task Body(CancellationToken stoppingToken) private async Task Body(CancellationToken stoppingToken)
{ {
if (!_IsWindowsService)
throw new EvaluateException("Set break point and skip!");
while (_IsWindowsService && !stoppingToken.IsCancellationRequested) while (_IsWindowsService && !stoppingToken.IsCancellationRequested)
{ {
Body(); Body();