Files icon indicating copy to clipboard operation
Files copied to clipboard

Code Quality: `FileLogger` should send logs to a `BackgroundService`

Open gumbarros opened this issue 1 year ago • 3 comments

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, ILogger is meant just to log the information, another class needs to do the heavy job

Requirements

  • Removing the IO operations from ILogger
  • Create a BackgroundService to 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

gumbarros avatar Mar 17 '24 20:03 gumbarros