Skip to main content

IsInfoEnabled Property​

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

Definition​

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

bool IsInfoEnabled { get; }

Property Value​

bool
true if informational messages are enabled; otherwise, false.

Example​

if (logger.IsInfoEnabled)
{
logger.Info(
"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 IsInfoEnabled to check if the level is enabled before calling the logging method, you can avoid this overhead when the log level is disabled.