Skip to content

Database logging ​

JASE.Database emits command traffic through Microsoft.Extensions.Logging (ILogger / ILoggerFactory). It is quiet by default. Turning on detailed SQL is an explicit host choice.

Logging is independent of Diagnostics. Leave Diagnostics at Off unless you need in-memory LastSQL / command history.

Goal: log every SQL statement (including DDL) ​

To see successful commands and the SQL text (create schema/table/index, queries, DML):

  1. Give the session a logger factory that can write to your sink.
  2. Set LogConfig.Command to Debug or Information.
  3. Set IncludeSqlText = true.
  4. Ensure the host logger allows Information (and Error for failures).
csharp
using JASE;
using JASE.Database;
using Microsoft.Extensions.Logging;

databaseConfig.Logging = new LogConfig
{
    Command = LogLevel.Debug,       // enables success + error gating
    IncludeSqlText = true,          // append "SQL: ..." lines
    LoggerFactory = new ForwardingLoggerFactory(appDatabaseLogger),
};

What you should see:

  • Success: Command executed. ... at Information, then SQL: <text> when IncludeSqlText is on
  • Failure: Command failed. ... at Error, then optional SQL text
  • Optional: parameter names/types/values via IncludeParameterTypes / IncludeParameterValues

DDL (drop/create schema, tables, indexes) goes through ExecuteNonQueryAsync and uses the Command category — not a separate Schema emit path today.

Two gates (both required) ​

GateWhat it controls
LogConfig.Command (default None)Whether JASE attempts to emit command events
Host ILogger.IsEnabled(level)Whether Serilog / MEL / NLog actually writes the event

Setting only LogConfig is not enough. If the host minimum level is Warning, success logs never appear even when Command = Debug.

Emit levels JASE uses ​

EventMEL level emitted
Successful commandInformation
Slow command (SlowQueryWarningMs)Warning
Failed commandError

Command = Debug still enables success logging; the event is raised as Information so typical file sinks receive it.

Logger factory resolution ​

First non-null wins:

  1. LogConfig.LoggerFactory (this connection / registration)
  2. JASE.Database.Configuration.LogFactory (Configuration.SetLogFactory)
  3. CoreConfig.LogFactory (CoreConfig.SetLogFactory — once-only)
  4. Null logger factory (discard)

Forwarding a named app logger ​

If the host already has ILogger named "Database" (or similar):

csharp
LoggerFactory = new ForwardingLoggerFactory(appDatabaseLogger)

ForwardingLoggerFactory (JASE Core) ignores category names and always returns that logger. It does not raise Serilog/MEL minimum levels — the wrapped logger must still allow Information/Error.

DatabaseConfig.Copy() ​

LoggerFactory is not serialized ([JsonIgnore]). Copy() preserves it explicitly. If you build your own clone path, re-assign Logging.LoggerFactory after copy.

Categories ​

ConstantValueUsed for
LogCategories.CommandJASE.Database.CommandCommand success / slow / failure (+ SQL text)
LogCategories.ReaderJASE.Database.ReaderReader open/dispose (gated by LogConfig.Reader)
LogCategories.LifecycleJASE.Database.LifecycleReserved
LogCategories.SchemaJASE.Database.SchemaReserved

When using a shared app factory (not forwarding), filter Serilog/MEL on JASE.Database or JASE.Database.Command at Information+.

Serilog / host checklist ​

If you see only exceptions:

  1. Confirm the package includes Information-level success emits.
  2. Confirm Logging is on the same session that runs the SQL.
  3. Confirm Command is not None.
  4. Confirm LoggerFactory is non-null after any config copy.
  5. Confirm appLogger.IsEnabled(LogLevel.Information) is true.
  6. In Serilog, check MinimumLevel / MinimumLevel.Override — Information must be allowed for that logger’s source.
  7. Look for the literal prefix Command executed. (JASE) vs your own catch-block messages.

Example Serilog override when using JASE category names (shared factory, no forwarding):

csharp
.MinimumLevel.Override("JASE.Database", LogEventLevel.Information)

With ForwardingLoggerFactory, configure the named logger / sink you wrap (e.g. your "Database" logger), not necessarily the JASE.Database.* source name.

Sensitivity ​

KnobRisk
IncludeSqlTextSQL may contain identifiers or inlined literals
IncludeParameterTypesUsually low risk
IncludeParameterValuesHigh — secrets / PII; keep off in production

Prefer parameters + IncludeSqlText without values for most diagnostics.