-
Notifications
You must be signed in to change notification settings - Fork 6
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.
In the C# examples on this page, these types are in Genetec.Sdk.Diagnostics (DiagnosticServer), Genetec.Sdk.Diagnostics.Logging.Core (Logger), and Genetec.Sdk.Diagnostics.Logging (DebugMethodAttribute, UserCommandAttribute).
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.
| Key | Type | Default | Description |
|---|---|---|---|
TraceExceptionStacks |
bool | true |
Include full exception stack traces |
IncludeThreadId |
bool | true |
Include thread ID in output |
<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.
| 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 the current working directory |
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 (for example, 500MB, 1GB) |
minDiskSpace |
string | (none) | Minimum free disk space to maintain |
maxFileSize |
string | (unlimited) | Maximum size per file (for example, 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 |
<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.
| Key | Type | Default | Description |
|---|---|---|---|
EventViewerLoggerName |
string | (system default) | Custom event log source name |
-
Error,Fatalmap to Windows Event Log Error -
Information,Performance,Debugmap to Windows Event Log Information -
Warningmaps to Windows Event Log Warning
<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.
| 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 (for example, 02:30 for 2:30 AM) |
MaxNumberOfErrors |
int | 10 |
Max connection errors before disabling target |
MaxWorkItems |
int | 2000 |
Max queued log entries |
<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.
| 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 |
<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).
| Key | Type | Default | Description |
|---|---|---|---|
TraceWithoutDebugger |
bool | false |
Output even when no debugger is attached |
HideExceptionStack |
bool | false |
Show only exception messages without stack traces |
<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).
| 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 |
<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.
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
<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
Security Desk and Config Tool include console ports in their .gconfig files:
- Security Desk:
http://localhost:6020/Console - Config Tool:
http://localhost:6021/Console
In the shipped configuration, the gNetServer element is disabled (enabled="false"), so these URLs are not served by default. To use one of these built-in consoles, enable gNetServer in the corresponding .gconfig file.
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.
Use these attributes to expose debug methods in the Diagnostic Console and control how they appear.
| 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")]These examples show the minimum attribute usage for instance and static debug methods.
[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.
-
About the Platform SDK: SDK assemblies and the
Engineclass. - Connecting to Security Center: Engine setup, authentication, and logging on to Security Center.
- Overview
- Connecting to Security Center
- SDK certificates
- Referencing SDK assemblies
- SDK compatibility
- Entities
- Entity cache
- Entity loading, cache, and query options
- Transactions
- Events
- Actions
- Security Desk
- Custom events
- ReportManager
- ReportManager query reference
- Access control raw events
- DownloadAllRelatedData and StrictResults
- Privileges
- Partitions
- About custom fields
- About video
- About cameras
- Enrolling a video unit
- Archiver and auxiliary archiver roles
- Archive transfer
- About access control
- About cardholders and credentials
- About doors, areas, elevators, and access points
- About access rules and schedules
- About access control units and interface modules
- Enrolling an access control unit
- Door templates
- Visitors
- Mobile credentials
- About threat levels
- About alarms
- Maps
- Logging
- Overview
- Certificates
- Lifecycle
- Threading
- State management
- Configuration
- Restricted configuration
- Events
- Queries
- Request manager
- Database
- Entity ownership
- Engine extensions
- Entity mappings
- Server management
- Custom privileges
- Custom entity types
- Resolving non-SDK assemblies
- Deploying plugins
- .NET 8 support
- Overview
- Certificates
- Creating modules
- Tasks
- Pages
- Components
- Tile extensions
- Services
- Contextual actions
- Options extensions
- Configuration pages
- Monitors
- Shared components
- Commands
- Extending events
- Map extensions
- Timeline providers
- Image extractors
- Credential encoders
- Credential readers
- Cardholder fields extractors
- Badge printers
- Content builders
- Dashboard widgets
- Incidents
- Logon providers
- Pinnable content builders
- Custom report pages
- Overview
- Getting started
- MediaPlayer
- VideoSourceFilter
- MediaExporter
- MediaFile
- G64 converters
- FileCryptingManager
- PlaybackSequenceQuerier
- PlaybackStreamReader
- OverlayFactory
- PtzCoordinatesManager
- AudioTransmitter
- AudioRecorder
- AnalogMonitorController
- Camera blocking
- Overview
- Getting started
- Referencing entities
- Entity operations
- About access control in the Web SDK
- About video in the Web SDK
- Users and user groups
- Partitions
- Custom fields
- Custom card formats
- Actions
- Events and alarms
- Incidents
- Reports
- Tasks
- Macros
- Custom entity types
- System endpoints
- Performance guide
- Reference
- Under the hood
- Troubleshooting