4.7 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T04:26:52.712375+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 93d08dfeda60c1f4 |
Logging
Purpose
This module provides centralized logging infrastructure for the DbAPI layer, abstracting the underlying logging mechanism (TextLogger) and exposing a simplified, type-safe interface for recording events with specific categories and severity levels. It ensures thread-safe initialization, enforces log level filtering, and writes all log entries to a rolling log file (DB.log) with standardized timestamping and formatting.
Public Interface
All members are internal (not public), per the internal class LogManager declaration. However, the module exposes the following static members accessible within the DbAPI.Logging namespace:
-
public static Sink DBAPILogWriter
A delegate of typeSink(fromDTS.Common.Utilities.Logging) assigned during initialization to theLogMsgmethod. It serves as the external-facing write endpoint for log messages. -
public static void Initialize(int logSize, string path, int minLog)
Initializes the logging system exactly once per application lifetime (idempotent due to early return if_LogWriteris non-null). Creates aTextLoggerwriting to{path}/DB.log, configures log rollover, sets the minimum log level (_MinLog), and assignsDBAPILogWriter.
Parameters:logSize: Maximum size (in bytes?) for the log file before rollover.path: Directory path whereDB.logwill be written.minLog: Bitwise combination ofTraceEventTypevalues (cast toint) defining the minimum severity to log (e.g.,Error | Warning).
-
public static void Log(TraceEventType eventType, LogEvents logEvent, string msg)
Logs a message if theeventTypemeets or exceeds the configured_MinLoglevel (via bitwise AND check). Formats the message with a timestamp, event type,LogEventscategory, and the providedmsg, then writes it viaLogMsg.
Parameters:eventType: Severity level (e.g.,TraceEventType.Error,Information).logEvent: Category from theLogEventsenum.msg: The log message text.
-
public static void OnWriteException(Exception ex)
Callback invoked byTextLoggeron write failures. Writes the exception message toConsole.Error.
Invariants
_LogWriteris initialized exactly once per AppDomain lifetime (enforced bylock+ null-check inInitialize).- Log messages are written only if
(minLog & (int)eventType) == (int)eventTypeholds (i.e., the event type is included in the configured minimum log level). - All log entries are prefixed with a fixed-format timestamp:
yyyy-MM-dd HH:mm:ss.fff. - The log file path is always
{path}/DB.log. _MinLogis set during initialization and never modified afterward.DBAPILogWriteris assigned only during the first call toInitializeand remains non-null thereafter.
Dependencies
- Imports/Usings:
DTS.Common.Utilities.Logging(providesSink,TextLogger,APILogger).System,System.Diagnostics,System.IO.
- External Types Used:
DTS.Common.Utilities.Logging.TextLogger(core logging implementation).DTS.Common.Utilities.Logging.APILogger(only referenced forSinktype viausing static).System.TraceEventType(severity levels).
- Depended Upon By:
- Other classes in the
DbAPIlayer (inferred from namespaceDbAPI.LoggingandDBAPILogWriterusage). - Not directly consumed by external consumers (all members are
internal).
- Other classes in the
Gotchas
- Thread Safety:
Initializeuses alockto prevent re-initialization, butLogandLogMsgare not explicitly synchronized. However,TextLoggeris assumed to be thread-safe (typical for such utilities). - Silent Failures:
LogMsgcatches and discards all exceptions during logging, potentially masking I/O errors (e.g., disk full, permission issues). - Hardcoded Log Filename: The log file is always named
DB.log, with no configurability. - Log Level Semantics:
_MinLoguses a bitwise mask againstTraceEventTypevalues. The default (Error | Warning) meansInformation,Verbose, etc., are excluded unless explicitly enabled. - No Cleanup: No
Disposeor shutdown logic is provided; resources (e.g., file handles) persist until process termination. - Timestamp Format: Milliseconds are zero-padded to 3 digits, but no timezone info is included (local time only).
- Enum Naming:
LogEventsis poorly named (implies events like "Connections", but actually represents categories or topics).