-
Notifications
You must be signed in to change notification settings - Fork 4
platform 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 in the SDK uses .gconfig files and Logger instances.
This does not require the DiagnosticServer.
-
Create a Configuration File
-
Name it after your executable, including
.exeand with.gconfigsuffix. -
Example: for
MyApp.exe, create:MyApp.exe.gconfig
-
-
Structure of the Configuration File
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<logTargets>
<!-- logTarget elements go here -->
</logTargets>
</configuration>-
Define Log Targets
You can define multiple
<logTarget>elements in the same.gconfigfile. 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>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 |
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>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>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>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>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>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>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>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>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 |
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.
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.
<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"
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.
The <traces> element is scoped per log target.
Each log target has its own <traces> block, and its filtering applies only to that target.
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 theGenetec.Dapnamespace. -
Genetec.Dap.MyClass: matches only the logger for the specific class. - Wildcards (
*) can be used for broader matching, such asGenetec.*.Samples.
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.
<traces>
<add loggerName="Genetec.Dap" severity="Information|Error" />
</traces><traces>
<add loggerName="Genetec.Dap.Module1" severity="Information|Error" />
<add loggerName="Genetec.Dap.Module2" severity="Warning|Error|Fatal" />
</traces>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.
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");
}
}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");
}
}The Logger class provides methods to log at each severity level:
TraceDebugTraceInformationTraceWarningTraceErrorTraceFatalTracePerformance
Each of these methods can accept:
- A simple message string.
- A message with
params object[]arguments. - An
Exceptionand optional message. - A
TraceEntryobject for advanced scenarios.
_logger.TraceDebug("Operation completed: {0}", operationId);
_logger.TraceError(new InvalidOperationException(), "Unexpected error.");- The
LoggerimplementsIDisposable. You should dispose instance loggers when no longer needed. - Class loggers remain valid for the lifetime of the application.
Available severity levels:
PerformanceDebugInformationWarningErrorFatal-
Full(all levels, including Performance and Debug) -
All(Information and higher, excluding Debug and Performance)
Combine severities with |, e.g.:
Warning | Error | Fatal
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.
- Hosts the web-based Diagnostic Console.
- Lists logs in real-time.
- Enables execution of debug methods marked with
DebugMethodAttribute.
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.
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
Dispose properly at shutdown:
if (DiagnosticServer.IsInstanceCreated && DiagnosticServer.Instance.IsInitialized)
{
DiagnosticServer.Instance.Dispose();
}Debug methods are application methods annotated to be discoverable and executable through the Diagnostic Console.
- A
Loggermust exist in the class defining the debug methods. - Methods can have any access modifier.
- Methods can return
stringorvoid. - If the class uses a static logger, methods must be
static. - If the class uses an instance logger, methods must be instance methods.
Each debug method must have a unique DisplayName within the same class.
Different classes may reuse the same DisplayName.
| 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. |
Groups the method into a category:
[UserCommand("Diagnostics.SampleCategory")][DebugMethod(DisplayName = "Instance Debug", Description = "Sample instance method")]
[UserCommand("Diagnostics")]
public string InstanceDebug()
{
return "Instance executed.";
}[DebugMethod(DisplayName = "Static Debug", Description = "Sample static method")]
[UserCommand("Diagnostics")]
public static string StaticDebug()
{
return "Static executed.";
}To adjust logging for built-in Security Center applications, modify:
SecurityDesk.exe.gconfigConfigTool.exe.gconfig
These are located in the Security Center installation folder.
-
Security Center SDK Developer Guide Overview of the SDK framework and how to build integrations with Security Center.
-
Platform SDK
- Platform SDK Overview Introduction to the Platform SDK and core concepts.
- SDK Certificates Details certificates, licensing, and connection validation.
- Entity Guide Explains the core entity model, inheritance, and how to work with entities.
- Entity Cache Guide Describes the engine's local entity cache and synchronization.
- SDK Transactions Covers batching operations for performance and consistency.
- ReportManager Querying entities and activity data from Security Center.
- Events and Actions Subscribing to events and handling actions.
- Logging with the Genetec SDK How to configure logging, diagnostics, and debug methods.
- Referencing SDK Assemblies Best practices for referencing assemblies and resolving them at runtime.
- SDK Compatibility Guide Understanding backward compatibility and versioning in the SDK.
-
Plugin SDK
- Plugin SDK Overview Introduction to plugin architecture and capabilities.
- Plugin SDK Certificates SDK certificate requirements for plugin roles.
- Plugin SDK Lifecycle Initialization and disposal patterns.
- Plugin SDK Threading Threading model, QueueUpdate, and async patterns.
- Plugin SDK Configuration Configuration storage and monitoring.
- Plugin SDK Restricted Configuration Secure credential storage and admin-only configuration.
- Plugin SDK Database Database integration and schema management.
- Plugin SDK Events Event subscription and handling.
- Plugin SDK Queries Query processing and response handling.
- Plugin SDK Request Manager Request/response communication with clients.
- Plugin SDK Entity Ownership Understanding plugin-owned entities, running state management, and ownership release.
- Plugin SDK Entity Mappings Using EntityMappings for plugin-specific configuration and external system integration.
- Plugin SDK State Management Reporting plugin health and diagnostics.
- Plugin SDK Server Management High availability and server failover.
- Custom Privileges Defining and enforcing custom privileges.
- Resolving Non-SDK Assemblies Handling third-party dependencies in plugins and workspace modules.
- Deploying Plugins Registering and deploying plugins and workspace modules.
-
- Macro SDK Developer Guide Complete guide to creating server-side automation scripts in Security Center using C#.
- 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 Guide Setup and configuration of the Media Gateway role for video streaming.
- Web Player Guide Complete guide to integrating GWP for live and playback video streaming.
- Web Player API Reference Full API documentation with interfaces, methods, properties, and events.
- Web Player Sample Application Comprehensive demo showcasing all GWP features with timeline and PTZ controls.
- Genetec Web Player Multiplexing Sample Multi-camera grid demo using a shared WebSocket connection.