GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
GenerallyPositive.GPALLogger Class Reference

Provides configurable logging to a file (in any format supported by GPALConverter) or to a GPALDatabase. Configuration is performed via a fluent interface (IAllowLoggingSettings / IAllowLoggingAndSetting), allowing the root directory, directory structure, filename pattern, delimiter, log type, and date format to be set before calling Log(dynamic). Errors and warnings encountered while logging are reported via GPAL.PublishSimpleEvent rather than throwing exceptions. More...

Inheritance diagram for GenerallyPositive.GPALLogger:
GenerallyPositive.IGPALLogger GenerallyPositive.IAllowLoggingSettings GenerallyPositive.IAllowLoggingAndSetting GenerallyPositive.IAllowToGPALObject< TResult > GenerallyPositive.IAllowToGPALObject< TResult > GenerallyPositive.IAllowLoggingSettings GenerallyPositive.IAllowToGPALObject< TResult >

Public Member Functions

IGPALLogger ToGPALObject ()
 Returns this instance as an IGPALLogger, completing the fluent configuration chain.
IAllowLoggingAndSetting WithLogEventTypes (GPALEventType logEventTypes)
 Sets the Enums.LogType (e.g. INFO, WARNING, ERROR) to be used for the next call to Log(dynamic). The log type is reset back to LogType.INFO after each Log(dynamic) call.
IAllowLoggingAndSetting WithLogType (LogType logType)
IAllowLoggingSettings WithDatabase (GPALDatabase database)
 Configures the logger to write log entries to a GPALDatabase instead of a file. When set, Log(dynamic) writes via GPALConverter.SaveTo(GPALDatabase) instead of to a file on disk.
IAllowLoggingSettings WithRootDirectory (string path)
 Sets the root directory under which log files are written. Subdirectories may be appended below this based on WithDirectoryStructure(DirectoryStructure). Defaults to the current working directory.
IAllowLoggingSettings WithDirectoryStructure (DirectoryStructure type)
 Sets the directory structure (e.g. year/month/day) created beneath the root directory for log files. The required directories are created automatically when a log entry is written.
IAllowLoggingSettings WithFilename (string name)
 Sets the base filename (including extension) used for log files. The extension determines the output DataFormat used by GPALConverter when writing log entries.
IAllowLoggingSettings WithFilenamePattern (FilenamePattern pattern)
 Sets a timestamp pattern that is appended to the filename (before the extension) each time a log file path is computed, allowing log files to be split by time period (e.g. one file per day).
IAllowLoggingAndSetting WithDelimiter (char delimiter)
 Sets the field delimiter used when writing log entries to a delimited text format. Also configures the underlying GPALConverter's input delimiter to match.
IAllowLoggingAndSetting WithLoggingFormat (LogDateFormat logDateFormat)
 Sets the date/time format applied to the timestamp prepended to each log entry by Log(dynamic). If not set, LogDateFormat.MDY_HMS is used.
IAllowLoggingAndSetting WithLogDateAsAttribute (bool logDateAsAttribute=true)
 Controls whether the log timestamp is written as an attribute rather than a regular field when the output format supports attributes (e.g. XML).
Public Member Functions inherited from GenerallyPositive.IAllowLoggingSettings
IAllowLoggingAndSetting WithLogType (Enums.LogType logType)

Static Public Member Functions

static string GetFormatString (LogDateFormat format)
 Translates a LogDateFormat value into the corresponding DateTime format string.

Properties

string LogDirectory [get]
 The folder the last entry was written to, with DirectoryStructure applied, e.g. logs\231. Null until something has been logged to a file.
string LogFilename [get]
 The name of the file the last entry was written to, with FilenamePattern applied, e.g. DeadMikes_20260819.log. Null until something has been logged to a file.
string LogFullPath [get]
 LogDirectory and LogFilename joined: the file the last entry went into. Null until something has been logged to a file.

Detailed Description

Provides configurable logging to a file (in any format supported by GPALConverter) or to a GPALDatabase. Configuration is performed via a fluent interface (IAllowLoggingSettings / IAllowLoggingAndSetting), allowing the root directory, directory structure, filename pattern, delimiter, log type, and date format to be set before calling Log(dynamic). Errors and warnings encountered while logging are reported via GPAL.PublishSimpleEvent rather than throwing exceptions.

.WithRootDirectory(@"C:\Logs")
.WithDirectoryStructure(DirectoryStructure.YMD)
.WithFilename("app.log")
.WithFilenamePattern(FilenamePattern.YMDHMS)
.WithLoggingFormat(LogDateFormat.YMD_HMS)
.WithLogType(LogType.INFO)
.Log("Application started");
static IAllowLoggingSettings Logger
New GPAL Logger.
Definition GPAL.cs:534

Definition at line 47 of file GPALLogger.cs.

Member Function Documentation

◆ GetFormatString()

string GenerallyPositive.GPALLogger.GetFormatString ( LogDateFormat format)
static

Translates a LogDateFormat value into the corresponding DateTime format string.

Parameters
formatThe log date format to translate.
Returns
A .NET date/time format string suitable for use with string.Format(string, object).
Exceptions
ArgumentExceptionThrown if format is not a recognized LogDateFormat value.

Definition at line 433 of file GPALLogger.cs.

◆ ToGPALObject()

IGPALLogger GenerallyPositive.GPALLogger.ToGPALObject ( )

Returns this instance as an IGPALLogger, completing the fluent configuration chain.

Returns
This logger, typed as IGPALLogger.

Implements GenerallyPositive.IAllowToGPALObject< TResult >.

Definition at line 88 of file GPALLogger.cs.

◆ WithDatabase()

IAllowLoggingSettings GenerallyPositive.GPALLogger.WithDatabase ( GPALDatabase database)

Configures the logger to write log entries to a GPALDatabase instead of a file. When set, Log(dynamic) writes via GPALConverter.SaveTo(GPALDatabase) instead of to a file on disk.

Parameters
databaseThe database to log entries to.
Returns
Fluent interface to continue logger configuration.

Implements GenerallyPositive.IAllowLoggingSettings.

Definition at line 135 of file GPALLogger.cs.

◆ WithDelimiter()

IAllowLoggingAndSetting GenerallyPositive.GPALLogger.WithDelimiter ( char delimiter)

Sets the field delimiter used when writing log entries to a delimited text format. Also configures the underlying GPALConverter's input delimiter to match.

Parameters
delimiterThe character used to separate fields in each log entry.
Returns
Fluent interface to continue logger configuration or logging.

Implements GenerallyPositive.IAllowLoggingSettings.

Definition at line 193 of file GPALLogger.cs.

◆ WithDirectoryStructure()

IAllowLoggingSettings GenerallyPositive.GPALLogger.WithDirectoryStructure ( DirectoryStructure type)

Sets the directory structure (e.g. year/month/day) created beneath the root directory for log files. The required directories are created automatically when a log entry is written.

Parameters
typeThe directory structure to use.
Returns
Fluent interface to continue logger configuration.

Implements GenerallyPositive.IAllowLoggingSettings.

Definition at line 158 of file GPALLogger.cs.

◆ WithFilename()

IAllowLoggingSettings GenerallyPositive.GPALLogger.WithFilename ( string name)

Sets the base filename (including extension) used for log files. The extension determines the output DataFormat used by GPALConverter when writing log entries.

Parameters
nameThe base filename, including extension (e.g. "app.log").
Returns
Fluent interface to continue logger configuration.

Implements GenerallyPositive.IAllowLoggingSettings.

Definition at line 170 of file GPALLogger.cs.

◆ WithFilenamePattern()

IAllowLoggingSettings GenerallyPositive.GPALLogger.WithFilenamePattern ( FilenamePattern pattern)

Sets a timestamp pattern that is appended to the filename (before the extension) each time a log file path is computed, allowing log files to be split by time period (e.g. one file per day).

Parameters
patternThe timestamp pattern to append to the filename.
Returns
Fluent interface to continue logger configuration.

Implements GenerallyPositive.IAllowLoggingSettings.

Definition at line 182 of file GPALLogger.cs.

◆ WithLogDateAsAttribute()

IAllowLoggingAndSetting GenerallyPositive.GPALLogger.WithLogDateAsAttribute ( bool logDateAsAttribute = true)

Controls whether the log timestamp is written as an attribute rather than a regular field when the output format supports attributes (e.g. XML).

Parameters
logDateAsAttributeTrue to write the timestamp as an attribute; defaults to true.
Returns
Fluent interface to continue logger configuration or logging.

Implements GenerallyPositive.IAllowLoggingSettings.

Definition at line 216 of file GPALLogger.cs.

◆ WithLogEventTypes()

IAllowLoggingAndSetting GenerallyPositive.GPALLogger.WithLogEventTypes ( GPALEventType logEventTypes)

Sets the Enums.LogType (e.g. INFO, WARNING, ERROR) to be used for the next call to Log(dynamic). The log type is reset back to LogType.INFO after each Log(dynamic) call.

Parameters
logTypeThe log type to apply to the next logged entry.
Returns
Fluent interface to continue logger configuration or logging.

Which event types this logger writes. Anything outside the set is dropped, whether GPAL published it or the workflow called .Log itself, so turning the set down quiets debug logging without deleting a single call.
Defaults to everything, so a logger that is never told stays as loud as it always was.

Parameters
logEventTypesThe event types to write
Returns
Fluent interface to define more logging settings

Implements GenerallyPositive.IAllowLoggingSettings.

Definition at line 118 of file GPALLogger.cs.

◆ WithLoggingFormat()

IAllowLoggingAndSetting GenerallyPositive.GPALLogger.WithLoggingFormat ( LogDateFormat logDateFormat)

Sets the date/time format applied to the timestamp prepended to each log entry by Log(dynamic). If not set, LogDateFormat.MDY_HMS is used.

Parameters
logDateFormatThe date/time format to use for log entry timestamps.
Returns
Fluent interface to continue logger configuration or logging.

Implements GenerallyPositive.IAllowLoggingSettings.

Definition at line 205 of file GPALLogger.cs.

◆ WithLogType()

IAllowLoggingAndSetting GenerallyPositive.GPALLogger.WithLogType ( LogType logType)

Definition at line 124 of file GPALLogger.cs.

◆ WithRootDirectory()

IAllowLoggingSettings GenerallyPositive.GPALLogger.WithRootDirectory ( string path)

Sets the root directory under which log files are written. Subdirectories may be appended below this based on WithDirectoryStructure(DirectoryStructure). Defaults to the current working directory.

Parameters
pathThe root directory path for log files.
Returns
Fluent interface to continue logger configuration.

Implements GenerallyPositive.IAllowLoggingSettings.

Definition at line 146 of file GPALLogger.cs.

Property Documentation

◆ LogDirectory

string GenerallyPositive.GPALLogger.LogDirectory
get

The folder the last entry was written to, with DirectoryStructure applied, e.g. logs\231. Null until something has been logged to a file.

Implements GenerallyPositive.IGPALLogger.

Definition at line 63 of file GPALLogger.cs.

◆ LogFilename

string GenerallyPositive.GPALLogger.LogFilename
get

The name of the file the last entry was written to, with FilenamePattern applied, e.g. DeadMikes_20260819.log. Null until something has been logged to a file.

Implements GenerallyPositive.IGPALLogger.

Definition at line 68 of file GPALLogger.cs.

◆ LogFullPath

string GenerallyPositive.GPALLogger.LogFullPath
get

LogDirectory and LogFilename joined: the file the last entry went into. Null until something has been logged to a file.

Implements GenerallyPositive.IGPALLogger.

Definition at line 73 of file GPALLogger.cs.


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