PDComm.Modbus.DiagnosticLogging
Class
Controls the optional diagnostic log of the PDComm Modbus native library.
public static class DiagnosticLoggingLogging is off by default. When enabled, the library writes JSON Lines records asynchronously to a file, with size-based rotation, or to standard error. The settings apply to the whole loaded pdcomm_modbus_ffi library, and records that cannot be queued are dropped and counted in DiagnosticLogging.Status. Requires Modbus ABI 1.1 or later.
Members
Configure
Method
Replaces the diagnostic log configuration.
public static void Configure(object options)Parameters
| Name | Description |
|---|---|
options | An object serialized to a JSON object with JsonSerializer, so use the exact lowercase names, for example an anonymous type. Recognized properties: enabled (bool, default true), level (error, warn, info, debug or trace; default info), file (a path, or null for standard error), max_bytes (rotation size, default 10 MiB), files (rotated files kept, 1 to 16, default 3) and forensics (bool; requires debug or trace). Unknown properties are rejected. |
Notes
- Throws
NotSupportedException: The loaded native library implements Modbus ABI 1.0, which has no logging API. - Throws
DllNotFoundException: The native library cannot be found or loaded. - Throws
InvalidOperationException: The library rejected the configuration.
Flush
Method
Waits until the queued log records have been written.
public static void Flush()Notes
- Throws
NotSupportedException: The loaded native library implements Modbus ABI 1.0, which has no logging API. - Throws
DllNotFoundException: The native library cannot be found or loaded. - Throws
InvalidOperationException: The writer did not confirm the flush within about two seconds, or it reported a write failure.
Status
Method
Gets the current logging state and counters.
public static JsonElement Status()Returns
A JSON object with fields such as enabled, level_name, sink, written, dropped, write_errors and configuration_errors.
Notes
- Throws
NotSupportedException: The loaded native library implements Modbus ABI 1.0, which has no logging API. - Throws
DllNotFoundException: The native library cannot be found or loaded. - Throws
InvalidOperationException: The library could not report its status.