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
- Reference NuGet package via using in your class:
using RollingFileWriter;- 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);
}- From created instance call method with incoming parameter as string or object:
WriteData(string data)OR
WriteData(object dataAsObject)- 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.
