# Logging

`File logging can be enabled from ServerConfig.xml it will log into a text file instead of console. Logs output dir is logs/filename.txt at root level of Application.`&#x20;

### Interface&#x20;

```csharp
namespace FigNet.Core
{
    public interface ILogger
    {
        void Error(string info);
        void Error(string info, params object[] args);
        void Exception(Exception exception, string info);
        void Exception(Exception exception, string info, params object[] args);
        void Info(string info);
        void Info(string info, params object[] args);
        void SetUp(bool enableFileLogging, string fileName);
        void Warning(string info);
        void Warning(string info, params object[] args);
    }
}
```

### Usage

```csharp
FN.Logger.Info("Hello FigNet");
```

### Logging Level

`FigNet provider following logging level that can be set or changed from ServerConfig.xml using LoggingLevel tag`

```markup
<LoggingLevel>INFO</LoggingLevel> <!--NONE, INFO, DEBUG, ALL-->
```

| Levels | Description                                                                                                                                      |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| NONE   | disable logging                                                                                                                                  |
| INFO   | print log messages as-is with timestep only                                                                                                      |
| DEBUG  | INFO + log info of data sent and received over network that includes Message Id, IsEncrypted, CallbackId,  DeliveryMode, ChannelId, Message Size |
| ALL    | DEBUG + log content of the message as hex code                                                                                                   |

`Example of Logging level set to DEBUG`

```bash
[13:31:26 INF] Received<= MessageId : 10 | IsEncrypted False | CallbackId 2 | SenderId 0 | MessageSize 12
[13:31:27 INF] Send=> MessageId : 10 | IsEncrypted False | CallbackId 2 | SendingTo 0 | DeliveryMode ReliableOrdered | ChannelId 0 | MessageSize 79
```

`Example of Logging level set to ALL`

```bash
[13:34:35 INF] Received<= MessageId : 10 |IsEncrypted False | CallbackId 2 | SenderId 0 | MessageSize 12 Message Content: ED-E1-3D-79-0A-00-02-91-81-00-CC-01
[13:34:35 INF] Send=> MessageId : 10 | IsEncrypted False | CallbackId 2 | SendingTo 0 | DeliveryMode ReliableOrdered | ChannelId 0 | MessageSize 79 Message Content: 48-B6-DD-D3-0A-00-02-91-81-00-D9-43-44-6F-6E-E2-80-99-74-20-79-6F-75-20-68-61-74-65-20-69-74-20-77-68-65-6E-20-73-6F-6D-65-6F-6E-65-20-61-6E-73-77-65-72-73-20-74-68-65-69-72-20-6F-77-6E-20-71-75-65-73-74-69-6F-6E-73-3F-20-49-20-64-6F-2E
```

### Helper Methods

`During troubleshooting when logging level is set to ALL, the logs become overwhelmed due to the amount of data being logs. FigNet provides helper methods that can be used to subscribe to particular messages only at runtime. If not message is subscribed then logger will print info for all network message else it will print logs of subscribed message only`

```csharp
// Note: These methods applies when Logging Level is set to ALL 
// FN.SubscribeToDetailedLog(10);
public static void SubscribeToDetailedLog(ushort messageId);
public static void UnSubscribeToDetailedLog(ushort messageId);
```

Or add SubscribeDebugMessages node in Configuration file&#x20;

```csharp
<SubscribeDebugMessages>
    <MessageInfo>
	<Id>10</Id>
    </MessageInfo>
    <MessageInfo>
	<Id>5</Id>
    </MessageInfo>
    <!--here add more messageInfos-->
</SubscribeDebugMessages>
```

On Unity side when logging level is set to all Add button will appear add message Ids as needed

![](/files/sA8ZumUOjyQtjJvuM56h)

{% hint style="info" %}

* `In Unity SDK default logger is a wrapper over unity’s Debug.Log`
* `Logs output dir is logs/.txt at root level of Application.`
  {% endhint %}


---

# 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://m-ahmed310.gitbook.io/fignet/core-concepts/logging.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.
