Skip to main content

Log Method

Writes a log entry at the specified level.

Definition​

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

Overloads​

NameDescription
Log(LogLevel, string)Writes a log entry at the specified level.
Log(LogLevel, string, string, object[])Writes a formatted log entry with a log code.
Log(LogLevel, string, Exception, string, object[])Writes a formatted log entry with a log code and exception.
Log(LogLevel, string, ILogContext, string, object[])Writes a formatted log entry with a log code and context.
Log(LogLevel, string, ILogContext, Exception, string, object[])Writes a formatted log entry with a log code, context, and exception.
Log(LogEvent)Writes a log entry described by a pre-built LogEvent.

Remarks​

This is a general-purpose logging method that can be used to write log entries at any level. The LogLevel parameter allows you to specify the severity of the log entry, while the various overloads provide flexibility in including additional information such as log codes, exceptions, and context.

This is particularly useful when the log level is known only at runtime. If the log level is known at compile time, it is generally more convenient to use the specific methods for each log level:

Trace Method
Debug Method
Info Method
Warning Method
Error Method
Fatal Method

The overloads of this method that include a code parameter allow you to specify a unique code (mnemonic or otherwise) that identifies the log message. See the Log Codes page for more information on log codes and how to use them effectively.


Log(LogLevel level, string message)​

Writes a log entry at the specified level with the given message.

void Log(LogLevel level, string message);

Parameters​

level LogLevel
The log level.

message string
The log message.


Log(LogLevel level, string code, string message, params object[] args)​

Writes a formatted log entry at the specified level with a log code.

void Log(LogLevel level, string code, string message, params object[] args);

Parameters​

level LogLevel
The log level.

code string
A unique code (mnemonic or otherwise) that identifies the log message.

message string
A string containing the message and format items to log.

args object[]
A params array of objects that match the format items in the message to provide them with values.


Log(LogLevel level, string code, Exception ex, string message, params object[] args)​

Writes a formatted log entry at the specified level with a log code and exception.

void Log(LogLevel level, string code, Exception ex, string message, params object[] args);

Parameters​

level LogLevel
The log level.

code string
The application-specific log code.

ex Exception
The exception to log.

message string
A string containing the message and format items to log.

args object[]
A params array of objects that match the format items in the message to provide them with values.


Log(LogLevel level, string code, ILogContext context, string message, params object[] args)​

Writes a formatted log entry at the specified level with a log code and context.

void Log(LogLevel level, string code, ILogContext context, string message, params object[] args);

Parameters​

level LogLevel
The log level.

code string
A unique code (mnemonic or otherwise) that identifies the log message.

context ILogContext
An instance to provide an additional log context to the log entry.

message string
A string containing the message and format items to log.

args object[]
A params array of objects that match the format items in the message to provide them with values.


Log(LogLevel level, string code, ILogContext context, Exception ex, string message, params object[] args)​

Writes a formatted log entry at the specified level with a log code, context, and exception.

void Log(LogLevel level, string code, ILogContext context, Exception ex, string message, params object[] args);

Parameters​

level LogLevel
The log level.

code string
A unique code (mnemonic or otherwise) that identifies the log message.

context ILogContext
Additional log context.

ex Exception
The exception to log.

message string
A string containing the message and format items to log.

args object[]
A params array of objects that match the format items in the message to provide them with values.


Log(LogEvent logEvent)​

Writes a log entry described by a pre-built LogEvent instance.

void Log(LogEvent logEvent);

Parameters​

logEvent LogEvent
The log event to write, including level, code, context, message, and arguments.

See Also​