GitHunt
LU

lukas9812/FileWriter

Project enables to save files with predefined custom name and its maximal size in MB. If this size is exceeded a new file with increment index is created.

NuGet usage:

NuGet: https://www.nuget.org/packages/RollingFileWriter

  1. Reference NuGet package via using in your class:
using RollingFileWriter;
  1. Choose among default or parameter constructor
  • Default ctor: Path is automatically set to "StoredData/Data_{DateTime.Today:dd_MM_yyyy}" and maximal file size is set to 500 MB. Values are not possible to configure.
public RollingFileWriterService()
   {
       _maximalFileSizeInMb = 500;
       Directory.CreateDirectory(_directoryPath);
       SetupFileName(string.Empty);
   }
  • Parameter ctor: Fully configurable values. If you'll not fill last parameter maximalFileSizeInMb maximal file size will be automatically set to 500 MB.
public RollingFileWriterService(string directoryPath, string fileName, int maximalFileSizeInMb = 500)
    {
        _maximalFileSizeInMb = maximalFileSizeInMb;
        _directoryPath = directoryPath;
        Directory.CreateDirectory(_directoryPath);
        SetupFileName(fileName);
    }
  1. From created instance call method with incoming parameter as string or object:
WriteData(string data)

OR

WriteData(object dataAsObject)
  1. All written data you can find in /bin folder under mentioned folder name.

Whole solution structure

The aim of this project is to develop an application that saves files with a preset size limit, specified in the appsettings.json file. If a file exceeds this size limit (in MB), a new file will be created with an incremented index added to the end of the file name (e.g., Data_26_07_2024_1, Data_26_07_2024_2, etc.).

Additionally, the application offers the option to filter specific properties to prevent the storage of unnecessary data.

Architecture:
image

Languages

C#100.0%

Contributors

Created July 25, 2024
Updated December 11, 2024
lukas9812/FileWriter | GitHunt