Skip to main content

Configuration Files

GatewayRuntime configuration files are stored under GatewayApp/Configuration/. The runtime loads appsettings.json first, then reads the JSON files in Configuration/. Use these files to adjust service ports, database connections, JWT security, log retention, OAuth2 login, and capacity limits.

Configuration File List

FilePurpose
WebApiOptions.jsonGatewayRuntime Web/API port and allowed cross-origin sources
Database.jsonDefault business database, backend log database, operation log database, and SQL log database connections
LoggerOptions.jsonProcess logs, gateway business logs, admin logs, retention policies, and ASP.NET log levels
JWTOptions.jsonToken issuer, expiration time, signing algorithm, token type, and secret
ChannelThread.jsonChannel check interval and channel, device, and variable capacity limits
IdGeneratorOptions.jsonSnowflake ID algorithm, base time, worker ID, and sequence settings
OAuth2Options.jsonOAuth2 login, callback address, default role, and external providers
SeedDataOptions.jsonWhether to force-refresh built-in users, roles, menus, and buttons

Directory Check

DirectoryDescription
DB/Default business database directory. The default SQLite file is ThingsGateway.db.
OTHERDB/Auxiliary databases for backend logs, operation logs, SQL logs, and related records.
Configuration/Runtime configuration files.
Logs/Runtime log files. The actual path follows the log configuration.
GatewayApp/GatewayRuntime program directory. Do not move or clean files while the runtime is running.

WebApiOptions

ItemDescriptionDefault
PortGatewayRuntime Web/API listening port6100
CorsOriginsAllowed cross-origin sources. Empty means all sources are allowed.Empty

Restart GatewayRuntime after changing the port. If Watchdog manages the runtime, also check the Gateway API port configured in Watchdog.

Database

ConfigIdDefault ConnectionPurpose
DefaultData Source=DB/ThingsGateway.db;journal mode=WALBusiness configuration, channels, devices, variables, scripts, nodes, and other core data
BackendData Source=OTHERDB/Backend.db;journal mode=WALBackend logs, channel logs, device logs, rule logs, and data forwarding logs
OperateData Source=OTHERDB/Operate.db;journal mode=WALOperation logs, RPC logs, and audit records
SqlLogData Source=OTHERDB/SqlLog.db;journal mode=WALSQL execution logs

The default SQLite connections explicitly enable WAL mode. When copying or backing up a running SQLite deployment, also account for possible -wal and -shm files. When switching to another database, confirm the connection string, database type, account permissions, and initialization plan before restarting the runtime.

LoggerOptions

ItemDescriptionDefault
LoggerOptions.LogLevelOverall process file log level: Trace, Debug, Info, Warning, Error, or CriticalInfo
LoggerOptions.ConsoleLogLevelConsole log level. Empty follows LogLevel.Info
LoggerOptions.LogPathFile log directory.Logs/XTrace
LoggerOptions.LogFileMaxMegabytesMaximum size of a single log file. 0 means unlimited.5
LoggerOptions.LogFileBackupsNumber of retained log files. 0 means unlimited.10
GatewayLogOptions.*DaysAgoRetention days for RPC, channel, device, rule engine, and data forwarding logs.30
GatewayLogOptions.*MaxRowCountMaximum retained rows for gateway business logs. 0 means unlimited.2000000, except rule engine 0
AdminLogOptions.*DaysAgoRetention days for operation, backend, SQL, and audit logs.30
AdminLogOptions.*MaxRowCountMaximum retained rows for admin logs. 0 means unlimited.2000000

JWTOptions

ItemDescription
IssuerToken issuer.
ExpiredTimeToken expiration time in minutes.
AlgorithmSigning algorithm.
TypeToken type.
SecretToken signing secret. Use an environment variable or a secure site-specific value in production.

Change the default secret before production use.

ChannelThread

ItemDescription
CheckIntervalChannel and device status check interval, in milliseconds.
MaxChannelCountMaximum allowed channel count.
MaxDeviceCountMaximum allowed device count.
MaxVariableCountMaximum allowed variable count.

The actual number of items that can be created is also limited by license and hardware resources.

OAuth2Options

ItemDescription
DefaultRoleId / DefaultRoleCodeDefault role used when OAuth2 creates a new user.
AutoCreateModeWhether first-time OAuth2 login can create a user automatically.
FrontendCallbackUrlFrontend callback address after OAuth2 login.
CallbackBaseUrlBackend callback base address.
ProvidersExternal login providers, such as GitHub.

The sample configuration contains a GitHub provider for demonstration. In production, create your own provider application and prefer environment variables for ClientId and ClientSecret. If external login is enabled, replace callback addresses according to the site network and HTTPS configuration.

IdGeneratorOptions

ItemDescription
MethodSnowflake algorithm type.
BaseTimeBase UTC time. It cannot be later than the current system time.
WorkerIdCurrent node worker ID.
WorkerIdBitLength / SeqBitLengthWorker ID and sequence bit lengths.
DataCenterIdData center ID.
TimestampTypeTimestamp unit.

Use different WorkerId values for different nodes in a multi-node deployment to avoid ID conflicts.

SeedDataOptions

ItemDescription
ForceUpdateMaster switch for force-refreshing built-in data.
ForceUpdateUsersWhether to refresh built-in users.
ForceUpdateRolesWhether to refresh built-in roles.
ForceUpdateMenusWhether to refresh menus.
ForceUpdateMenuLocalesWhether to refresh menu localization.
ForceUpdateButtonsWhether to refresh button permissions.

Back up the database before enabling force refresh in a production system with customized users, roles, or menus.