Skip to content

platform sdk logging

Andre Lafleur edited this page Dec 11, 2025 · 2 revisions

About SDK logging

The Genetec SDK provides a flexible logging framework and an optional diagnostic interface.

Basic logging allows your application to write trace messages at configurable severity levels to destinations such as files, console, Event Viewer, SQL Server, and others. This is configured through .gconfig files and uses the Logger class at runtime.

DiagnosticServer is an optional component you can initialize in your application. It hosts a web-based Diagnostic Console where you can view logs in real time and execute specially annotated application methods called debug methods. Debug methods are useful for interactive testing and diagnostics while the application is running.

If you only need your application to generate logs, you can configure and use the logging facilities without enabling the DiagnosticServer. You only need to initialize the DiagnosticServer if you want to expose the Diagnostic Console and enable debug methods.

Basic logging

Basic logging in the SDK uses .gconfig files and Logger instances. This does not require the DiagnosticServer.

Setting Up Log Traces for an External Application

  1. Create a Configuration File

    • Name it after your executable, including .exe and with .gconfig suffix.

    • Example: for MyApp.exe, create:

      MyApp.exe.gconfig
      
  2. Structure of the Configuration File

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <logTargets>
    <!-- logTarget elements go here -->
  </logTargets>
</configuration>
  1. Define Log Targets You can define multiple <logTarget> elements in the same .gconfig file. Each log target is independent, and logs matching its <traces> configuration will be written to all applicable targets.
<logTarget type="Genetec.Diagnostics.Logging.Targets.ConsoleTarget, Genetec">
  <settings>
    <add key="TraceExceptionStacks" value="true" />
    <add key="IncludeThreadId" value="true" />
  </settings>
  <traces>
    <add loggerName="MyCompany.MyProject.*" severity="Warning | Error | Fatal"/>
    <add loggerName="MyCompany.MyProject.MyClass" severity="Performance"/>
  </traces>
</logTarget>

Available log targets

The SDK provides the following log targets:

Target Type Name Description
Console Genetec.Diagnostics.Logging.Targets.ConsoleTarget, Genetec Outputs to console window
Log File Genetec.Diagnostics.Logging.Targets.LogFileTarget, Genetec Writes to flat text files
Event Log Genetec.Diagnostics.Logging.Targets.EventLogTarget, Genetec Writes to Windows Event Log
SQL Server Genetec.Diagnostics.Logging.Targets.SqlServerLogTarget, Genetec Writes to SQL Server database
XML Genetec.Diagnostics.Logging.Targets.XmlLogTarget, Genetec Writes to XML files (.gtrace)
Debug Genetec.Diagnostics.Logging.Targets.DebugTarget, Genetec Outputs to debug window (Visual Studio)
ETW Genetec.Diagnostics.Logging.Targets.EtwLogTarget, Genetec Event Tracing for Windows
OTLP Genetec.Diagnostics.Logging.Targets.OtlpTarget, Genetec OpenTelemetry Protocol exporter

ConsoleTarget

Outputs log messages to the console window.

Settings:

Key Type Default Description
TraceExceptionStacks bool true Include full exception stack traces
IncludeThreadId bool true Include thread ID in output

Example:

<logTarget type="Genetec.Diagnostics.Logging.Targets.ConsoleTarget, Genetec">
  <settings>
    <add key="TraceExceptionStacks" value="true" />
    <add key="IncludeThreadId" value="true" />
  </settings>
  <traces>
    <add loggerName="MyCompany.*" severity="All" />
  </traces>
</logTarget>

LogFileTarget

Writes log messages to flat text files. Files are created in a Logs folder by default.

Settings:

Key Type Default Description
prefix string (empty) Prefix for log file names
logFolder string Logs Folder path for log files. Use %EXE% pattern for path relative to executable
deleteOlderThanNDays int 14 Delete log files older than this many days
logMaxLine int (unlimited) Maximum lines per file before creating a new file
maxDiskUsage string (unlimited) Maximum total disk usage (e.g., 500MB, 1GB)
minDiskSpace string (none) Minimum free disk space to maintain
maxFileSize string (unlimited) Maximum size per file (e.g., 100MB)
zipFiles bool false Compress old log files
detailedHeader bool true Write detailed header at file start
format string Text Log format: Text or Json
reuseFiles bool true Reuse existing log files (vs. always create new)
prefixWithMachineName bool false Prefix file names with machine name

Example:

<logTarget type="Genetec.Diagnostics.Logging.Targets.LogFileTarget, Genetec">
  <settings>
    <add key="prefix" value="MyApp" />
    <add key="logFolder" value="C:\Logs\MyApp" />
    <add key="deleteOlderThanNDays" value="30" />
    <add key="maxFileSize" value="50MB" />
  </settings>
  <traces>
    <add loggerName="MyCompany.*" severity="All" />
  </traces>
</logTarget>

EventLogTarget

Writes log messages to the Windows Event Log.

Settings:

Key Type Default Description
EventViewerLoggerName string (system default) Custom event log source name

Severity mapping:

  • Error, Fatal → Windows Event Log Error
  • Information, Performance, Debug → Windows Event Log Information
  • Warning → Windows Event Log Warning

Example:

<logTarget type="Genetec.Diagnostics.Logging.Targets.EventLogTarget, Genetec">
  <settings>
    <add key="EventViewerLoggerName" value="MyApplication" />
  </settings>
  <traces>
    <add loggerName="MyCompany.*" severity="Error | Fatal" />
  </traces>
</logTarget>

SqlServerLogTarget

Writes log messages to a SQL Server database. Automatically creates the required LogEntry table.

Settings:

Key Type Default Description
Server string (required) SQL Server instance name
Database string (required) Database name
MaxLogEntries int 10000 Maximum entries to keep in database
CleanupTime TimeSpan 00:00 Time of day to run cleanup (e.g., 02:30 for 2:30 AM)
MaxNumberOfErrors int 10 Max connection errors before disabling target
MaxWorkItems int 2000 Max queued log entries

Example:

<logTarget type="Genetec.Diagnostics.Logging.Targets.SqlServerLogTarget, Genetec">
  <settings>
    <add key="Server" value="localhost\SQLEXPRESS" />
    <add key="Database" value="ApplicationLogs" />
    <add key="MaxLogEntries" value="50000" />
    <add key="CleanupTime" value="03:00" />
  </settings>
  <traces>
    <add loggerName="MyCompany.*" severity="Warning | Error | Fatal" />
  </traces>
</logTarget>

XmlLogTarget

Writes log messages to XML files with .gtrace extension.

Settings:

Key Type Default Description
prefix string (empty) Prefix for file names
logFolder string Logs Folder path for log files
maximumFileSizeInMegabytes int 100 Maximum file size in MB before rotation
totalMaximumFileSizeInMegabytes int 1024 Maximum total size of all log files
retentionPeriodInDays int -1 (disabled) Delete files older than this many days

Example:

<logTarget type="Genetec.Diagnostics.Logging.Targets.XmlLogTarget, Genetec">
  <settings>
    <add key="prefix" value="MyApp" />
    <add key="logFolder" value="C:\Logs\Traces" />
    <add key="maximumFileSizeInMegabytes" value="50" />
    <add key="retentionPeriodInDays" value="7" />
  </settings>
  <traces>
    <add loggerName="MyCompany.*" severity="Full" />
  </traces>
</logTarget>

DebugTarget

Outputs log messages to the debug output window (visible in Visual Studio when debugging).

Settings:

Key Type Default Description
TraceWithoutDebugger bool false Output even when no debugger is attached
HideExceptionStack bool false Show only exception messages without stack traces

Example:

<logTarget type="Genetec.Diagnostics.Logging.Targets.DebugTarget, Genetec">
  <settings>
    <add key="TraceWithoutDebugger" value="false" />
    <add key="HideExceptionStack" value="false" />
  </settings>
  <traces>
    <add loggerName="MyCompany.*" severity="Full" />
  </traces>
</logTarget>

EtwLogTarget

Writes log messages using Event Tracing for Windows (ETW).

Settings:

Key Type Default Description
providerName string (required) ETW provider name
autoRegisterEventLog bool false Automatically register the event log provider
eventLogMaxSizeInMegabyte int 100 Maximum event log size in MB

Example:

<logTarget type="Genetec.Diagnostics.Logging.Targets.EtwLogTarget, Genetec">
  <settings>
    <add key="providerName" value="MyCompany-MyApp" />
    <add key="autoRegisterEventLog" value="true" />
    <add key="eventLogMaxSizeInMegabyte" value="200" />
  </settings>
  <traces>
    <add loggerName="MyCompany.*" severity="All" />
  </traces>
</logTarget>

OtlpTarget

Exports log messages using the OpenTelemetry Protocol (OTLP). Requires an OTLP-compatible collector endpoint.

Settings:

This target uses the standard OpenTelemetry OTLP exporter configuration through environment variables:

  • OTEL_EXPORTER_OTLP_ENDPOINT - The OTLP collector endpoint
  • OTEL_EXPORTER_OTLP_HEADERS - Headers for authentication

Example:

<logTarget type="Genetec.Diagnostics.Logging.Targets.OtlpTarget, Genetec">
  <traces>
    <add loggerName="MyCompany.*" severity="All" />
  </traces>
</logTarget>

Common settings

These settings are available on all log targets and are configured in the <settings> element:

Key Type Default Description
summarize int (disabled) Summarize repeated messages within this time window (milliseconds)
domainFilter string (all) Wildcard filter to enable target only for specific AppDomain names

summarize

When the same log message is written repeatedly in a short time (for example, in a loop or during rapid event processing), the log file can become flooded with duplicate entries. The summarize setting collapses these repeated messages into a single entry within the specified time window.

Set the value in milliseconds. For example, 5000 means repeated messages within 5 seconds are summarized.

domainFilter

Security Center runs multiple processes, each with its own AppDomain name. The domainFilter setting restricts a log target to only write logs from processes whose AppDomain name matches the wildcard pattern.

Use standard wildcard characters: * matches any characters, ? matches a single character.

Example

<logTarget type="Genetec.Diagnostics.Logging.Targets.LogFileTarget, Genetec">
  <settings>
    <add key="summarize" value="5000" />
    <add key="domainFilter" value="MyPlugin*" />
  </settings>
  <traces>
    <add loggerName="MyCompany.*" severity="All" />
  </traces>
</logTarget>

This configuration:

  • Summarizes repeated log messages that occur within 5 seconds
  • Only writes logs from AppDomains whose name starts with "MyPlugin"

Traces element

Each <logTarget> contains a <traces> element, which defines which loggers and severity levels this log target listens to.

You can think of <traces> as a filter for the specific log target. Only log messages that match a loggerName and a specified severity inside <traces> will be written to that log target. Messages that do not match any <add /> in <traces> are ignored by that target, but may still go to other targets.

Scope

The <traces> element is scoped per log target. Each log target has its own <traces> block, and its filtering applies only to that target.

Logger Name

The loggerName refers to the fully qualified logger name, which typically includes the namespace and optionally the class name. For example:

  • Genetec.Dap : matches all loggers in the Genetec.Dap namespace.
  • Genetec.Dap.MyClass : matches only the logger for the specific class.
  • Wildcards (*) can be used for broader matching, such as Genetec.*.Samples.

Multiple <add /> Elements

You can include multiple <add /> elements inside a single <traces> block. Each one specifies a loggerName and a severity. All <add /> elements are cumulative: if any of them matches a log message, that message is written to the target.


Example: Single <add />

<traces>
  <add loggerName="Genetec.Dap" severity="Information|Error" />
</traces>

Example: Multiple <add />

<traces>
  <add loggerName="Genetec.Dap.Module1" severity="Information|Error" />
  <add loggerName="Genetec.Dap.Module2" severity="Warning|Error|Fatal" />
</traces>

The Logger Class

The Logger class is used in your application code to emit log messages at different severity levels. It works in conjunction with the .gconfig file, which defines where and which messages are written.

You can create either an instance logger or a class logger, depending on your use case.

Instance Logger

Use an instance logger when you want a logger tied to a specific instance of your class.

class InstanceLogger : IDisposable
{
    private readonly Logger m_logger;

    public InstanceLogger()
    {
        m_logger = Logger.CreateInstanceLogger(this);
    }

    public void Dispose()
    {
        m_logger.Dispose();
    }

    public void LogDebugMessage()
    {
        m_logger.TraceDebug("This is a debug message");
    }
}

Class (Static) Logger

Use a class logger when you want a single logger shared across all instances of a class.

static class StaticLogger
{
    private static readonly Logger s_logger = Logger.CreateClassLogger(typeof(StaticLogger));

    public static void LogDebugMessage()
    {
        s_logger.TraceDebug("This is a debug message");
    }
}

Logging Methods

The Logger class provides methods to log at each severity level:

  • TraceDebug
  • TraceInformation
  • TraceWarning
  • TraceError
  • TraceFatal
  • TracePerformance

Each of these methods can accept:

  • A simple message string.
  • A message with params object[] arguments.
  • An Exception and optional message.
  • A TraceEntry object for advanced scenarios.

Example Usage

_logger.TraceDebug("Operation completed: {0}", operationId);
_logger.TraceError(new InvalidOperationException(), "Unexpected error.");

Notes

  • The Logger implements IDisposable. You should dispose instance loggers when no longer needed.
  • Class loggers remain valid for the lifetime of the application.

Log Severities

Available severity levels:

  • Performance
  • Debug
  • Information
  • Warning
  • Error
  • Fatal
  • Full (all levels, including Performance and Debug)
  • All (Information and higher, excluding Debug and Performance)

Combine severities with |, e.g.:

Warning | Error | Fatal

DiagnosticServer

The DiagnosticServer provides a web-based console that lets you view logs interactively and execute annotated debug methods at runtime. It is not required for basic logging.

What It Does

  • Hosts the web-based Diagnostic Console.
  • Lists logs in real-time.
  • Enables execution of debug methods marked with DebugMethodAttribute.

Example Initialization

const int diagnosticServerPort = 4523;
const int webServerPort = 6023;

DiagnosticServer.Instance.InitializeServer(diagnosticServerPort, webServerPort);
  • There is no default webServerPort. You must specify it explicitly.
  • Requires administrative privileges to bind ports.

Accessing the Console

After initialization, open the console in your browser:

http://localhost:<webServerPort>/Console

Built-in consoles for Security Desk and Config Tool are also accessible at:

  • Security Desk: http://localhost:6020/Genetec/Overview
  • Config Tool: http://localhost:6021/Genetec/Overview

Cleanup

Dispose properly at shutdown:

if (DiagnosticServer.IsInstanceCreated && DiagnosticServer.Instance.IsInitialized)
{
    DiagnosticServer.Instance.Dispose();
}

Using Debug Methods

Debug methods are application methods annotated to be discoverable and executable through the Diagnostic Console.

Requirements

  • A Logger must exist in the class defining the debug methods.
  • Methods can have any access modifier.
  • Methods can return string or void.
  • If the class uses a static logger, methods must be static.
  • If the class uses an instance logger, methods must be instance methods.

Unique DisplayName per Class

Each debug method must have a unique DisplayName within the same class. Different classes may reuse the same DisplayName.

Attributes

DebugMethodAttribute

Property Description
Description Description shown in the console.
DisplayName Unique per class.
IsHidden Hides the method from the list; can still be invoked by manually entering its DisplayName.
IsSecured Restricts execution to the local machine.

UserCommandAttribute

Groups the method into a category:

[UserCommand("Diagnostics.SampleCategory")]

Examples

Instance Debug Method

[DebugMethod(DisplayName = "Instance Debug", Description = "Sample instance method")]
[UserCommand("Diagnostics")]
public string InstanceDebug()
{
    return "Instance executed.";
}

Static Debug Method

[DebugMethod(DisplayName = "Static Debug", Description = "Sample static method")]
[UserCommand("Diagnostics")]
public static string StaticDebug()
{
    return "Static executed.";
}

Configuring Logging for Security Desk and Config Tool

To adjust logging for built-in Security Center applications, modify:

  • SecurityDesk.exe.gconfig
  • ConfigTool.exe.gconfig

These are located in the Security Center installation folder.

Security Center SDK


Macro SDK Developer Guide


Web SDK Developer Guide

  • Getting Started Setup, authentication, and basic configuration for the Web SDK.
  • Referencing Entities Entity discovery, search capabilities, and parameter formats.
  • Entity Operations CRUD operations, multi-value fields, and method execution.
  • Partitions Managing partitions, entity membership, and user access control.
  • Custom Fields Creating, reading, writing, and filtering custom entity fields.
  • Custom Card Formats Managing custom credential card format definitions.
  • Actions Control operations for doors, cameras, macros, and notifications.
  • Events and Alarms Real-time event monitoring, alarm monitoring, and custom events.
  • Incidents Incident management, creation, and attachment handling.
  • Reports Activity reports, entity queries, and historical data retrieval.
  • Performance Guide Optimization tips and best practices for efficient API usage.
  • Reference Entity GUIDs, EntityType enumeration, and EventType enumeration.
  • Under the Hood Technical architecture, query reflection, and SDK internals.
  • Troubleshooting Common error resolution and debugging techniques.

Media Gateway Developer Guide


Web Player Developer Guide

Clone this wiki locally