Design Pattern Examples
Overview of object-oriented design patterns
Logger Class Reference

Represents the logger object to be used in the program. More...

Inheritance diagram for Logger:
Inheritance graph
Collaboration diagram for Logger:
Collaboration graph

Public Types

enum  LoggerTypes { ToNull , ToFile , ToConsole }
 A value passed to Logger.Logger() constructor to specify the type of logger to create. More...
 

Public Member Functions

 Logger (LoggerTypes loggerType, params string[] arguments)
 Constructor that takes a LoggerTypes value and optional arguments to create a new Logger class.
 
void LogTrace (string message)
 Log trace messages to the configured output.
 
void LogInfo (string message)
 Log informational messages to the configured output.
 
void LogError (string message)
 Log error messages to the configured output.
 

Private Member Functions

void IDisposable. Dispose ()
 Dispose of this logger object in a friendly way.
 

Private Attributes

ILogger_logger
 The logger implementation represented by the ILogger interface.
 

Detailed Description

Represents the logger object to be used in the program.

This class wraps different implementations of loggers to show the Bridge Pattern.

Definition at line 15 of file Bridge_Logger.cs.

Member Enumeration Documentation

◆ LoggerTypes

A value passed to Logger.Logger() constructor to specify the type of logger to create.

Enumerator
ToNull 

Log to nowhere, that is, throw out all logging. No additional parameters.

ToFile 

Log to a file. One additional parameter: the name of the file to log to.

ToConsole 

Log to the console. No additional parameters.

Definition at line 21 of file Bridge_Logger.cs.

Constructor & Destructor Documentation

◆ Logger()

Logger ( LoggerTypes  loggerType,
params string[]  arguments 
)
inline

Constructor that takes a LoggerTypes value and optional arguments to create a new Logger class.

Parameters
loggerTypeA value from the LoggerTypes enum specifying the type of logger object to create.
argumentsZero or more additional arguments that some logger types require. For example, a file logger requires a filename.

Definition at line 47 of file Bridge_Logger.cs.

References Logger._logger, ConsoleLogger.CreateConsoleLogger(), FileLogger.CreateFileLogger(), and NullLogger.CreateNullLogger().

Member Function Documentation

◆ Dispose()

void IDisposable. Dispose ( )
inlineprivate

Dispose of this logger object in a friendly way.

Definition at line 124 of file Bridge_Logger.cs.

References Logger._logger.

◆ LogError()

void LogError ( string  message)
inline

Log error messages to the configured output.

Parameters
messageThe message to log.

Definition at line 111 of file Bridge_Logger.cs.

References Logger._logger, and ILogger.LogError().

Referenced by Bridge_Exercise._Bridge_Exercise_Demonstrate_Logging().

◆ LogInfo()

void LogInfo ( string  message)
inline

Log informational messages to the configured output.

Parameters
messageThe message to log.

Definition at line 99 of file Bridge_Logger.cs.

References Logger._logger, and ILogger.LogInfo().

Referenced by Bridge_Exercise._Bridge_Exercise_Demonstrate_Logging().

◆ LogTrace()

void LogTrace ( string  message)
inline

Log trace messages to the configured output.

Parameters
messageThe message to log.

Definition at line 87 of file Bridge_Logger.cs.

References Logger._logger, and ILogger.LogTrace().

Referenced by Bridge_Exercise._Bridge_Exercise_Demonstrate_Logging().

Member Data Documentation

◆ _logger

ILogger? _logger
private

The logger implementation represented by the ILogger interface.

Definition at line 140 of file Bridge_Logger.cs.

Referenced by Logger.__exit__(), Logger.Close(), Logger.Dispose(), Logger.LogError(), Logger.Logger(), Logger.LogInfo(), and Logger.LogTrace().


The documentation for this class was generated from the following file: