Logging information - TheModderWasReplaced/AgriCore GitHub Wiki

Logging information is an important piece of any mod. It is what allows modders and players to understand what the mods are doing. Here is how to log information, how to toggle certain levels of logging and when each level should be used.

How to Log information

They are multiple ways to access the logging feature. All you need is to have access to a ManualLogSource object. However, here is the code for my logging system:

internal static class Log
{
    private static ManualLogSource _logger;
    
    public static void SetLogger(ManualLogSource logger) => _logger = logger;
    
    private static void LogSelf(object data, LogLevel level) => _logger?.Log(level, data ?? "null");
    public static void Debug(object data) => LogSelf(data, LogLevel.Debug);
    public static void Info(object data) => LogSelf(data, LogLevel.Message);
    public static void Warning(object data) => LogSelf(data, LogLevel.Warning);
    public static void Error(object data) => LogSelf(data, LogLevel.Error);
}

With this, all you need to do is call Log.SetLogger(Logger) inside the Awake() of your mod. You will then be able to log values from anywhere in your mod.

How to Toggle Levels of Logging

By default, not all levels of logging are shown in the console. In order to change that, go to BepInEx, config then open BepInEx.cfg. You need to change the value of LogLevels under the Logging.Console section.

When to use Each Level

Here is a diagram that explains when you should use each level:

4suKr7673WR0dHH5

Thank you Lethal Company's Modding Server