Skip to main content

IsTraceEnabled Property​

Gets a value indicating whether LogLevel.Trace messages are enabled.

Definition​

Namespace: GHost.Core.Logging
Type: ILogger
Assembly: GHost.Core.dll

bool IsTraceEnabled { get; }

Property Value​

bool
true if trace-level messages are enabled; otherwise, false.

Example​

if (logger.IsTraceEnabled)
{
logger.Trace(
"UserDet",
"User {User} logged in",
GetUserFullDetails()); // Expensive method to get user details
}

Remarks​

Use this property to check if a log level is enabled before performing expensive operations to generate log messages, such as string formatting or gathering contextual information.

The logger is designed to be as efficient as possible when a log is disabled, but a call to a logging method with a message that contains string formatting items will still incur the cost of computing and sending the arguments, even if the specified level is disabled. For many arguments this is not an issue, but if the arguments are expensive to compute, this can lead to unnecessary overhead when the log level is disabled.

By using IsTraceEnabled to check if the level is enabled before calling the logging method, you can avoid this overhead when the log level is disabled.