# File Logger

Let's create a logger with name **TestLogger**

This modded script should be created in *Module #3 - 3\_Game,* so you can access that across the whole app. Otherwise you can choose a different place. I just think it's convenient to have it accessible from most of the codebase of DayZ Server.&#x20;

```csharp
// Create a modded class for DayZGame script
modded class DayZGame
{
    override void CRDTN_OnGameInit()
    {
        super.CRDTN_OnGameInit();
        CRDTN_FileLogger.CreateInstance("TestLogger");
        // instantiates the instance of FileLogger with key - TestLogger
        // 
    }
};
```

Congratulations, you have create your logger :joy: The file will be saved in ***$profile/CRDTN/Logs/TestLogger.log***

If you want a different location for your logs, you must rewrite the constant&#x20;

```c
CFG_CRDTN_LogsFolder
```

Now you can access it from your code wherever you need by using the following code snippet.

```c
CRDTN_FileLogger.GetInstance("TestLogger").Log("Some of your message");
```

You can also cache the reference for more convenient work like below.&#x20;

```csharp
class TestPlugin : CRDTN_PluginBase
{
    private ref CRDTN_FileLogger m_TestLogger;
    
    override void OnInit()
    {
        super.OnInit();
        m_TestLogger = CRDTN_FileLogger.GetInstance("TestLogger");
    }
    
    CRDTN_FileLogger GetTestLogger()
    {
        return m_TestLogger;
    }
};

TestPlugin GetTestPlugin()
{
    if (!GetGame().IsServer())
    {
        return NULL;
    }

    if (GetPluginManager() && GetPluginManager().GetPluginByType(TestPlugin))
    {
        return TestPlugin.Cast(GetPluginManager().GetPluginByType(TestPlugin));
    }

    return NULL;
}

CRDTN_TestLogger GetLogger()
{
    return GetTestPlugin().GetTestLogger();
}
```

If you have followed the code above, you now can just call in the code&#x20;

```csharp
GetLogger().Log("Some message");
```

Be aware, that the example showcases usage of **PluginBase** which is part of module #4 so you can use the **GetLogger()** method only within module #4 and #5.&#x20;
