Files
DP44/docs/ai/DataPRO/DbAPI/Logging.md
2026-04-17 14:55:32 -04:00

2.1 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/DbAPI/Logging/LogManager.cs
2026-04-17T16:14:40.267853+00:00 zai-org/GLM-5-FP8 1 60dc472c9df3ec54

Logging

Purpose

This module provides centralized logging infrastructure for the DbAPI system. It wraps a TextLogger to write timestamped, categorized log messages to a file named "DB.log" with support for log rotation, filtering by severity level, and thread-safe initialization. The module exposes a delegate-based sink (DBAPILogWriter) that can be used by other components to write raw log messages.

Public Interface

LogManager (internal class)

  • static Sink DBAPILogWriter - Public field assigned to the internal LogMsg method; allows external code to write raw strings to the log.
  • enum LogEvents - Public enum defining log event categories: Message, Connections, Login, Information, DataRecorders, Graphs, CalculatedChannels, Sensors, TestSetups, RegionsOfInterest, Tags.
  • static void Initialize(int logSize, string path, int minLog) - Initializes the logger with the specified file size limit, directory path, and minimum log level filter. Creates "DB.log" in the given path. Thread-safe; subsequent calls are no-ops if already initialized.
  • static void Log(TraceEventType eventType, LogEvents logEvent, string msg) - Logs a message with the specified event type and category. Respects the _MinLog filter; messages whose event type is not in the filter are silently dropped.
  • static void OnWriteException(Exception ex) - Callback for handling write exceptions; writes the exception message to Console.Error.

Invariants

  • _LogWriter is singleton-initialized; once set, Initialize returns immediately without reinitializing.
  • Initialization is guarded by lock(MyLock) for thread safety.
  • _MinLog defaults to (TraceEventType.Error | TraceEventType.Warning) if Initialize is not called or if minLog is not applied.
  • Log filtering uses bitwise AND: a message is logged only if (_MinLog & (int)eventType) == (int)eventType.

Dependencies

  • Depends on: DTS.Common.Utilities.Logging (pro