Logger

Database Logging

WithDatabase attaches a GPALDatabase instance to the logger. When a database is configured, GPAL writes log entries to the database table in addition to (or instead of) any file output. Configure the database object with GPAL.Database first - set the connection string, table name, and any relevant SQL commands - then pass it to the logger via WithDatabase. ToGPALObject returns the IGPALLogger interface.

Examples

GPAL Fluent: High-level fluent C# API

//WithDatabase routes log entries to the specified database table. The table must have columns that match the log entry structure GPAL expects. Combine WithDatabase and WithRootDirectory to write to both a file and a database simultaneously.

// Log to a database table

var logDb = GPAL.Database

.WithConnectionString(connStr)

.WithTableName("AppLog")

.ToGPALObject();


GPAL.Logger

.Log("User action recorded")

.WithLogType(LogType.Info)

.WithLoggingFormat(LogDateFormat.YearMonthDayHourMinuteSecond)

.WithDatabase(logDb);

💬 Ask GPAL