Writing content to a media
To manage the complexity of code isolation, let's declare a C# interface which will manage the idiosyncrasies of multiple log targets:
public interface IContentWriter { Task<bool> Write(string content); }
The basic idea here, is that the concrete classes which implement the interface should provide an implementation of this method that writes the log to the respective media. But on closer inspection, we find that it is better to write a base class implementation of this method and its associated semantics in an abstract class. The base class implementation can add a log entry to a queue (that would give concurrency support), flush the queue, and persist to target the media when a threshold (configured) is reached. A ...
Get .NET Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.