# ILoggerService

Namespace: **Wisej.AI.Services**

Assembly: **Wisej.AI** (3.5.0.0)

Defines a contract for logging services that support logging messages with a specified trace level and optional formatting arguments.

{% tabs %}
{% tab title="C#" %}

```csharp
public interface ILoggerService
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Interface ILoggerService
```

{% endtab %}
{% endtabs %}

Implementations of this interface should provide a mechanism for logging messages that include a specified [TraceLevel](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracelevel) and a message string. The message can include formatting placeholders that are replaced by the provided arguments. This interface is typically used in applications that require logging capabilities to track the flow of execution and capture debugging information.

## Methods

### ![](/files/ptrKjmmRoQB76pvrIqh0) Log(level, context, message, arguments)

Logs a message with a specified trace level and optional formatting arguments.

| Parameter     | Type                                                                              | Description                                                                                                                       |
| ------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **level**     | [TraceLevel](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracelevel) | The [TraceLevel](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracelevel) indicating the severity of the log message. |
| **context**   | [String](https://docs.microsoft.com/dotnet/api/system.string)                     | A string representing the name of the class and the method that called the logger.                                                |
| **message**   | [String](https://docs.microsoft.com/dotnet/api/system.string)                     | The message to log. This may contain format placeholders.                                                                         |
| **arguments** | [Object\[\]](https://docs.microsoft.com/dotnet/api/system.object)                 | Optional. An array of objects to format into the message. Default is an empty array.                                              |

This method allows the caller to log a message at a specified trace level. The message may include placeholders that will be replaced by the provided arguments.\
Example usage:

```csharp

  ILoggerService logger = new ConsoleLoggerService();
  logger.Log(TraceLevel.Info, "User {0} has logged in at {1}.", "JohnDoe", DateTime.Now);

```

The method should handle any necessary formatting of the message string with the arguments provided and then record the log entry with the appropriate trace level.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Log(level, context, exception)

Logs an exception with a specified trace level.

| Parameter     | Type                                                                              | Description                                                                                                                       |
| ------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **level**     | [TraceLevel](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracelevel) | The [TraceLevel](https://docs.microsoft.com/dotnet/api/system.diagnostics.tracelevel) indicating the severity of the log message. |
| **context**   | [String](https://docs.microsoft.com/dotnet/api/system.string)                     | A string representing the name of the class and the method that called the logger.                                                |
| **exception** | [Exception](https://docs.microsoft.com/dotnet/api/system.exception)               | The exception to be logged, which provides the message and stack trace.                                                           |

This method is designed to log exceptions at a specified trace level, capturing the exception's message and stack trace.\
Example usage:

```csharp

try
{
// Some code that might throw an exception
}
catch (Exception ex)
{
ILoggerService logger = Application.Services.GetService<ILoggerService>();
logger.Log(TraceLevel.Error, ex);
}

```

This method simplifies the process of logging exceptions by automatically including essential details such as the exception message and stack trace.

## Implemented By

| Name                                                                                        | Description                                                                                                                                   |
| ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| [DefaultLoggerService](https://docs.wisej.com/api?q=wisej.ai.services.defaultloggerservice) | Provides a default implementation of the [ILoggerService](/ai/components/api/services/iloggerservice.md) for logging messages and exceptions. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/api/services/iloggerservice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
