DotNet.Host.LogFilesMonitorArchiver 8.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNet.Host.LogFilesMonitorArchiver --version 8.1.0                
NuGet\Install-Package DotNet.Host.LogFilesMonitorArchiver -Version 8.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNet.Host.LogFilesMonitorArchiver" Version="8.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNet.Host.LogFilesMonitorArchiver --version 8.1.0                
#r "nuget: DotNet.Host.LogFilesMonitorArchiver, 8.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotNet.Host.LogFilesMonitorArchiver as a Cake Addin
#addin nuget:?package=DotNet.Host.LogFilesMonitorArchiver&version=8.1.0

// Install DotNet.Host.LogFilesMonitorArchiver as a Cake Tool
#tool nuget:?package=DotNet.Host.LogFilesMonitorArchiver&version=8.1.0                

.NET Core Logging Files Monitor and Archiver

Long running services can generate lots of logging and temporary files. They become outdated and should be deleted by the dedicated period of time, like 180 days. ".NET Core Logging Files Monitor and Archiver" provides convenient and flexible features for log files archiving and removing. ".NET Core Logging Files Monitor and Archiver" is a long running monitor which scans file directories, archives them and deletes the old. It keeps file directories in tidy state by the rules.

Version 8.1.0
  • Add support of .Net 8.x
  • Obsolete "MoveToArchiveAfterReachingFiles" replaced with MoveToArchiveAfterReachingNumber
  • Obsolete "DeleteFromArchiveAfterReachingFiles" replaced with DeleteFromArchiveAfterReachingNumber
  • Add MonitoringMode:
    • FilesOnly
    • SubdirectoriesOnly
  • Property AutoTimerIntervalEnabled is not supported, Auto Timer Interval always on.

ASP.NET Core WebHost and Host edition of ".NET Core Logging Files Monitor and Archiver": https://www.nuget.org/packages/DotNet.Host.LogFilesMonitorArchiver/

Archive scenarios

The "DotNet.LogFilesMonitorArchiver" package allows to implement the following archive scenarios:

  1. Monitoring the "SourcePath" directory by the list of search pattern "MonitoringNames" names.

  2. For each matched file name in the "SourcePath" directory apply the rules:

  • Move it into the archive directory "ArchivePath" if the file created date is older than configured "MoveToArchiveOlderThanDays" days (default value 7).
  • Move it into the archive directory "ArchivePath" if the number of files is greater than configured "MoveToArchiveAfterReachingNumber" number S(default value is int.MaxValue).
  1. For each matched file name in the "ArchivePath" directory apply the rules:
  • Delete it from the archive directory "ArchivePath" if the file created date is older than configured "DeleteFromArchiveOlderThanDays" days (default value 30).
  • Delete it from the archive directory "ArchivePath" if the number of files is greater than configured "DeleteFromArchiveAfterReachingNumber" number (default value is int.MaxValue).

Hosted via IHostedService

Use https://www.nuget.org/packages/DotNet.Host.LogFilesMonitorArchiver/ package.

Create separate configuration file or add to existing appsettings.config the root configuration section with name "ArchiveProcessorConfig".

Example of the configuration section:

{

 "ArchiveProcessorConfig": {
   "ArchiveOnStartup": "true",
   "DelayArchiveInSecondsOnstartUp": 1, 
   "AutoTimerArchiveIntervalMin": 720,
   "ArchiveRules": [
    {
      "SourcePath": "\\Logs\\AppExampleLogSource\\Stat",
      "ArchivePath": "\\Logs\\AppExampleLogSource\\Stat\\Archive",
      "MonitoringNames": [ "archive-able_*.xml", "*.csv" ],
      "MoveToArchiveOlderThanDays": 14,
      "MoveToArchiveAfterReachingNumbers": 28,
      "DeleteFromArchiveOlderThanDays": 180,
      "DeleteFromArchiveAfterReachingNumbers": 1000
    },
    {
      "UseUtcTime":"false",
      "SourcePath": "\\Logs\\AppExampleLogSource\\FatalError",
      "ArchivePath": "\\Logs\\AppExampleLogSource\\FatalError\\Archive",
      "MonitoringNames": [ "archive-able_*.xml", "*.trace" ],
      "MoveToArchiveOlderThanDays": 7,
      "DeleteFromArchiveOlderThanDays": 360
    }
  ]
 }
}

When configuring services add the following initialization code into:


var builder = WebApplication.CreateBuilder(args);

....

builder.Services.AddLogFilesMonitorArchiver();

builder.Services.AddLogFilesMonitorArchiverConfiguration(builder.Configuration);

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.0 72 1/5/2025
8.1.0 78 1/5/2025
8.0.0 82 12/8/2024
6.0.0 483 8/3/2022
5.0.0 434 2/7/2021
3.1.0 550 10/3/2020
3.0.0 570 10/17/2019
2.4.0 644 3/24/2019
2.3.1 819 9/24/2018
2.3.0 933 6/4/2018
2.2.0 995 4/29/2018
2.1.0 971 1/10/2018

Released only for net8.0
     Singed assembly.
     Implements StartAsync and StopAsync via Microsoft.Extensions.Hosting.IHostedService.