Mid From PDF GoF Patterns Gang of Four Patterns

Concrete Handlers:?

  • The InfoLogger and ErrorLogger are concrete handlers that implement

the Logger class. Each handler checks if it can handle a particular log level

(e.g., Info or Error). If it can, it processes the log; otherwise, it passes it along

to the next handler in the chain.

public class InfoLogger : Logger
{

protected override bool CanHandle(LogLevel level) => level ==

LogLevel.Info;

protected override void Handle(string message) =>

Console.WriteLine($"Info: {message}");

}
public class ErrorLogger : Logger
{

protected override bool CanHandle(LogLevel level) => level ==

LogLevel.Error;

protected override void Handle(string message) =>

Console.WriteLine($"Error: {message}");

}

More from Design Patterns in C#

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details