Logger

Attaching a Logger and Entry Format

GPAL.Logger begins the chain and ToGPALObject ends it, returning an IGPALLogger. GPAL.WithPublishToLogger attaches it so that published events start writing entries, and GPAL.RemoveLogger detaches it. Attaching the same logger twice is rejected with a warning rather than doubling every entry. WithLogEventTypes sets which GPALEventType values this logger writes, defaulting to all of them. GPALEventType.NONE writes nothing. The severity on a line is the published event's own type, so there is nothing to set it to. WithLoggingFormat sets the entry timestamp format using the LogDateFormat enum. WithDelimiter sets the character between the fields on the line, defaulting to the pipe, and can be changed on an attached logger at any time. LogDirectory, LogFilename, and LogFullPath report where the logger actually wrote, which the directory structure and filename pattern may have decided rather than you.

Examples

GPAL Fluent: High-level fluent C# API

//An entry line is timestamp, event type, calling method, message. The calling method is the one that raised the event, not the one that wrote it, so the line points at the code that did the work. Loggers accumulate: attach as many as the run needs and each writes only the types it subscribed to. An event with no message writes NULL rather than an empty field, so a line never silently loses a column.

// Build, then attach. Nothing is written until an event is published

IGPALLogger logger = GPAL.Logger

.WithRootDirectory(@"C:Logs")

.WithFilename("app.log")

.ToGPALObject();


GPAL.WithPublishToLogger(logger);


GPAL.PublishSimpleEvent(GPALEventType.NOTICE, "Process started");

// 2026-08-21 09:15:00 | NOTICE | Main | Process started


// Only the failures, in commas, with a full timestamp

IGPALLogger errors = GPAL.Logger

.WithRootDirectory(@"C:Logs")

.WithFilename("errors.log")

.ToGPALObject();


errors.WithLogEventTypes(GPALEventType.ERROR | GPALEventType.EXCEPTION)

.WithLoggingFormat(LogDateFormat.YMD_HMS)

.WithDelimiter(',');


GPAL.WithPublishToLogger(errors);


// Done with this phase

GPAL.RemoveLogger(errors);


// Where it wrote

GPALFile written = errors.LogFullPath;

💬 Ask GPAL