Skip to Content
TUtilityLogging and runtime information

Logging and runtime information

On this page

Library logging

TUtility’s TUtility.Log.XTrace supplies a shared entry point:

using TUtility.Log; using TouchSocket.Core; XTrace.Write("Device worker started.", LogLevel.Info);

WriteException retains exception details. Hosts can select an ILog through XTrace.Log. ConsoleLog, TextFileLog and LoggerGroup provide console, file and combined output. Initialize global logging centrally.

Host file logging

TUtility.App’s AddTextFileLog(configuration) extension uses the Microsoft.Extensions.DependencyInjection namespace. It registers shared TextFileLog, MicrosoftLog and combined ILog services, with disposal owned by DI. Business logs reach both the file and Microsoft logging pipelines.

{ "LoggerOptions": { "LogLevel": "Info", "ConsoleLogLevel": "Warning", "LogPath": "Logs/XTrace", "LogFileMaxMegabytes": 5, "LogFileBackups": 10, "LogFileFormat": "{0:yyyy_MM_dd}.log" } }

This registration method requires positive size and backup limits, plus non-empty path and format. Lower-level logger settings allowing zero for unlimited output do not apply here. Individual entries also have a budget; store large payloads elsewhere and log references.

Configure file and Microsoft / console filtering separately. Paths resolve against AppDataPaths.RootDirectory. Verify permissions and disk capacity at deployment. Request handlers must not dispose DI-owned loggers.

Time and environment

Runtime.TickCount64 and Runtime.AppTickCount64 are millisecond counters for elapsed time. They are not Unix timestamps or UTC values comparable across machines. Persist events with explicit timezone semantics and convert for display.

MachineInfo.GetCurrent() returns a machine-information sample. Field availability varies by platform and container. Read container limits separately from host physical resources.

Remove credentials and sensitive data before recording configurations, URLs or request bodies. See TAdmin logging for auditing and log queues.