PDComm.DiagnosticLogging
Class
Controls the optional diagnostic log of the PDComm SECS/GEM 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 library, not to one endpoint, and the log never blocks protocol work: records that cannot be queued are dropped and counted in DiagnosticLogging.Status.
The native library can also be configured before startup with the PDCOMM_LOG, PDCOMM_LOG_FILE, PDCOMM_LOG_MAX_BYTES, PDCOMM_LOG_FILES and PDCOMM_LOG_FORENSICS environment variables.
PDComm.PdcommRuntime.Initialize(args[0]);
PDComm.DiagnosticLogging.Configure(new { enabled = true, level = "debug", file = args[1] });
using (var buffer = PDComm.PdcommBuffer.Create(new byte[] { 1, 2, 3 }, 1024)) { }
PDComm.DiagnosticLogging.Flush();
Console.WriteLine(PDComm.DiagnosticLogging.Status());
PDComm.DiagnosticLogging.Configure(new { enabled = false });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 does not export the logging API. - Throws
InvalidOperationException: The library rejected the configuration, for example an unknown property, an invalid level or limit, or a log file that cannot be opened.
Flush
Method
Waits until the queued log records have been written.
public static void Flush()Notes
- Throws
NotSupportedException: The loaded native library does not export the logging API. - Throws
InvalidOperationException: The writer did not confirm the flush within the library's wait limit of 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 does not export the logging API. - Throws
InvalidOperationException: The library could not report its status.