Please report any issues here
Offers simple methods for adding debug logs to method calls. Also provides a variety of log formatting options to users.
Drag the LoggingApi.dll
to your BepInEx/plugins
folder, or just install the mod via a Thunderstore mod loader.
Add the following to your project's .csproj
file, replacing [FILEPATH]
with the path to the LoggingApi.dll
<ItemGroup>
<Reference Include="LoggingApi">
<HintPath>[FILEPATH]\LoggingApi.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
New loggers are created using a ManualLogSource
and LogLevel
.
- The log source is typically your plugins
base.Logger
- It is recommended to use pass a log level set by a config for your plugin.
- This allows user to change the level of logs shown.
- View the BepInEx documentation on how to create configs.
Here is an example of how to set up a global logger for your plugin.
public class Plugin : BaseUnityPlugin
{
internal static LoggingApi.Logger MyLogger; // Global logger for the plugin
internal static ConfigEntry<LogLevel> ConfigLogLevel; // Config to control which logs are shown
...
private void Awake()
{
MyLogger = LoggingApi.Logger(base.Logger, ConfigLogLevel) // Create a new logger
MyLogger.Log(LogLevel.Message, "Hello World!")
MyLogger.LogMessage("Hello World!")
}
}
// Some other class in the plugin assembly
class SomeOtherAssembly
{
public void SomeMethod()
{
Plugin.MyLogger.LogMessage("Hello World!")
}
}
With the logger class you can log all calls to members of a type or just specific members of the type.
public class Plugin : BaseUnityPlugin
{
internal static LoggingApi.Logger MyLogger; // Global logger for the plugin
internal static ConfigEntry<LogLevel> ConfigLogLevel; // Config to control which logs are shown
...
private void Awake()
{
MyLogger = LoggingApi.Logger(base.Logger, ConfigLogLevel) // Create a new logger
MyLogger.LogAllCalls(typeof(SomeOtherAssembly)) // All type members
MyLogger.LogCalls(typeof(SomeOtherAssembly), LoggingApi.SearchFlags.Public) // Only public type members
}
}
// Some other class in the plugin assembly
class SomeOtherAssembly
{
public void SomeMethod()
{
...
}
}
Flags to filter which type members are included in a search.