Files
Files copied to clipboard
Code Quality: `FileLogger` should send logs to a `BackgroundService`
Description
FileLogger should send logs to a BackgroundService because ILogger is not meant to do IO operations.
Related issue: https://github.com/dotnet/extensions/issues/2141
Related discussion: https://github.com/dotnet/runtime/discussions/87949
Concerned code
https://github.com/files-community/Files/blob/39c2f9cb4ebf16c6ad21f1737672b4fac829eae4/src/Files.Shared/Utils/Logger/FileLogger.cs
Gains
- Better performance, logging would not block the app thread writing to the file
- Separations of concerns,
ILoggeris meant just to log the information, another class needs to do the heavy job
Requirements
- Removing the IO operations from
ILogger - Create a
BackgroundServiceto run the IO operations requested by a buffer
Comments
Example FileLogger implementation:
https://github.com/JJConsulting/JJMasterData/blob/main/src/Commons/Logging/File/FileLogger.cs
Example FileLogger background service:
https://github.com/JJConsulting/JJMasterData/blob/main/src/Commons/Logging/File/FileLoggerBackgroundService.cs