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

Represents a logger to a file. More...

Inheritance diagram for FileLogger:
Inheritance graph
Collaboration diagram for FileLogger:
Collaboration graph

Public Member Functions

 FileLogger (string filename)
 Constructor. If successful, the file is opened for writing. Raises an exception if the output file cannot be created.
 
void LogTrace (string msg)
 Log trace messages to the configured output.
 
void LogInfo (string msg)
 Log informational messages to the configured output.
 
void LogError (string msg)
 Log error messages to the configured output.
 

Static Public Member Functions

static ILogger CreateFileLogger (string filename)
 Create an instance of a file logger.
 

Private Member Functions

void _WriteLine (string logLevel, string msg)
 Write a formatted line to the log.
 
void ILogger. LogTrace (string msg)
 Log trace messages to the configured output.
 
void ILogger. LogInfo (string msg)
 Log informational messages to the configured output.
 
void ILogger. LogError (string msg)
 Log error messages to the configured output.
 
void IDisposable. Dispose ()
 Close the log file gracefully.
 

Private Attributes

StreamWriter _outputFile
 
bool _disposed
 

Detailed Description

Represents a logger to a file.

Definition at line 18 of file Bridge_FIleLogger.cs.

Constructor & Destructor Documentation

◆ FileLogger()

FileLogger ( string  filename)
inline

Constructor. If successful, the file is opened for writing. Raises an exception if the output file cannot be created.

Parameters
filenameName of file to log to.
Exceptions
UnauthorizedAccessException"The caller does not have the required permission.", "path specified a file that is read-only.", or "path specified a file that is hidden."
ArgumentExceptionpath is a zero-length string, contains only white space, or contains one or more invalid characters.
ArgumentNullExceptionpath is null.
PathTooLongExceptionThe specified path, file name, or both exceed the system-defined maximum length.
DirectoryNotFoundExceptionThe specified path is invalid (for example, it is on an unmapped drive).
NotSupportedExceptionpath is in an invalid format.

Definition at line 40 of file Bridge_FIleLogger.cs.

References FileLogger._outputFile, and DesignPatternExamples_csharp.File.

Member Function Documentation

◆ _WriteLine()

void _WriteLine ( string  logLevel,
string  msg 
)
inlineprivate

Write a formatted line to the log.

Parameters
logLevelThe level of the log detail.
msgThe message to log.

Definition at line 51 of file Bridge_FIleLogger.cs.

References FileLogger._outputFile, and LoggerHelpers.FormatLogLine().

Referenced by ConsoleLogger.LogError(), FileLogger.LogError(), ConsoleLogger.LogInfo(), FileLogger.LogInfo(), ConsoleLogger.LogTrace(), and FileLogger.LogTrace().

◆ CreateFileLogger()

static ILogger CreateFileLogger ( string  filename)
inlinestatic

Create an instance of a file logger.

Parameters
filenameThe filename to log to.
Returns
An instance of an ILogger object.

Definition at line 98 of file Bridge_FIleLogger.cs.

Referenced by Logger.Logger().

◆ Dispose()

void IDisposable. Dispose ( )
inlineprivate

Close the log file gracefully.

Definition at line 81 of file Bridge_FIleLogger.cs.

References FileLogger._disposed, and FileLogger._outputFile.

◆ LogError()

void ILogger. LogError ( string  msg)
inlineprivate

Log error messages to the configured output.

Parameters
msgThe message to log.

Implements ILogger.

Definition at line 69 of file Bridge_FIleLogger.cs.

References FileLogger._WriteLine().

◆ LogInfo()

void ILogger. LogInfo ( string  msg)
inlineprivate

Log informational messages to the configured output.

Parameters
msgThe message to log.

Implements ILogger.

Definition at line 64 of file Bridge_FIleLogger.cs.

References FileLogger._WriteLine().

◆ LogTrace()

void ILogger. LogTrace ( string  msg)
inlineprivate

Log trace messages to the configured output.

Parameters
msgThe message to log.

Implements ILogger.

Definition at line 59 of file Bridge_FIleLogger.cs.

References FileLogger._WriteLine().

Member Data Documentation

◆ _disposed

bool _disposed
private

Definition at line 21 of file Bridge_FIleLogger.cs.

Referenced by FileLogger.Dispose().

◆ _outputFile

StreamWriter _outputFile
private

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