Skip to content

Code Quality: FileLogger should send logs to a BackgroundService #14979

@gumbarros

Description

@gumbarros

Description

FileLogger should send logs to a BackgroundService because ILogger is not meant to do IO operations.

Related issue:
dotnet/extensions#2141

Related discussion:
dotnet/runtime#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions