Abstract and inject the logger instance #82

Closed
opened 2 months ago by kimimaru · 2 comments
Owner

Create a new generic TRBotLogger class that takes in a type argument. This type argument will be used to show which class the logs are coming from.

Create a static CreateLog<T> method to create a logger of that type. For example,
TRBotLogger<BotProgram> Logger = TRBotLogger.CreateLog<BotProgram>() creates a logger using BotProgram as the type.

Whenever an instance logs something, it should prepend the type to the message. In the example above, if a messaged was logged with Logger.Information("Test"), the output should be "[BotProgram] Test".

A secondary effect of this allows instantiating different types of loggers for different purposes. Overall, this will reduce dependencies on a static logger instance and give us more detailed logs.

Create a new generic `TRBotLogger` class that takes in a type argument. This type argument will be used to show which class the logs are coming from. Create a static `CreateLog<T>` method to create a logger of that type. For example, `TRBotLogger<BotProgram> Logger = TRBotLogger.CreateLog<BotProgram>()` creates a logger using `BotProgram` as the type. Whenever an instance logs something, it should prepend the type to the message. In the example above, if a messaged was logged with `Logger.Information("Test")`, the output should be **"[BotProgram] Test"**. A secondary effect of this allows instantiating different types of loggers for different purposes. Overall, this will reduce dependencies on a static logger instance and give us more detailed logs.
kimimaru added the
refactor
label 2 months ago
kimimaru added this to the TRBot 2.4 project 2 months ago
Poster
Owner

Change of plans. This would create a ton of loggers and would not be efficient. It may also cause IO problems since multiple loggers would be writing to the same file.

Instead, inject the instance of the ILogger interface where it's needed and use that instance.

Change of plans. This would create a ton of loggers and would not be efficient. It may also cause IO problems since multiple loggers would be writing to the same file. Instead, inject the instance of the `ILogger` interface where it's needed and use that instance.
kimimaru changed title from Adjust logging project for more detailed messages to Abstract and inject the logger instance 1 month ago
Poster
Owner

Completed in f9d96a3820. It's much cleaner now!

Completed in https://codeberg.org/kimimaru/TRBot/commit/f9d96a382075d3c3d0e11f7b67ef79879dc9660e. It's much cleaner now!
kimimaru closed this issue 1 month ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.