Appearance
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):
- Give the session a logger factory that can write to your sink.
- Set
LogConfig.CommandtoDebugorInformation. - Set
IncludeSqlText = true. - 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, thenSQL: <text>whenIncludeSqlTextis 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)
| Gate | What 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
| Event | MEL level emitted |
|---|---|
| Successful command | Information |
Slow command (SlowQueryWarningMs) | Warning |
| Failed command | Error |
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:
LogConfig.LoggerFactory(this connection / registration)JASE.Database.Configuration.LogFactory(Configuration.SetLogFactory)CoreConfig.LogFactory(CoreConfig.SetLogFactory— once-only)- 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
| Constant | Value | Used for |
|---|---|---|
LogCategories.Command | JASE.Database.Command | Command success / slow / failure (+ SQL text) |
LogCategories.Reader | JASE.Database.Reader | Reader open/dispose (gated by LogConfig.Reader) |
LogCategories.Lifecycle | JASE.Database.Lifecycle | Reserved |
LogCategories.Schema | JASE.Database.Schema | Reserved |
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:
- Confirm the package includes Information-level success emits.
- Confirm
Loggingis on the same session that runs the SQL. - Confirm
Commandis notNone. - Confirm
LoggerFactoryis non-null after any config copy. - Confirm
appLogger.IsEnabled(LogLevel.Information)istrue. - In Serilog, check
MinimumLevel/MinimumLevel.Override— Information must be allowed for that logger’s source. - 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
| Knob | Risk |
|---|---|
IncludeSqlText | SQL may contain identifiers or inlined literals |
IncludeParameterTypes | Usually low risk |
IncludeParameterValues | High — secrets / PII; keep off in production |
Prefer parameters + IncludeSqlText without values for most diagnostics.
Related API
LogConfigLogCategoriesConfiguration.LogFactory(library-wide)ForwardingLoggerFactoryin JASE CoreDiagnostics— in-memory only; not required for file/SQL logging