Class Logger
Provides a logger implementation that integrates with BepInEx's logging system.
Logs level can be adjusted setting ActiveLogLevels
Logs can be filtered by log level and tags, allowing for flexible logging configurations.
- ActiveTags for assigning active tags to the logger.
- InactiveTags for assigning tags that should be suppressed in logs.
private static readonly Logger logger = Logger.Create(typeof(MyPluginClass), LogTags.MyCustomTag);
logger.Debug("This is an debug message with {} argument.", "example");
logger.Info("This is an info message with {} argument.", "example");
logger.Warn("This is a warning message with {} argument.", "example");
logger.Error("This is an error message with an exception.", ex);
logger.Fatal("This is a fatal message with an exception.", ex);
public class Logger : ILogger
- Inheritance
-
Logger
- Implements
- Inherited Members
- Extension Methods
Constructors
Logger(ManualLogSource, string, params ILogTag[])
Provides a logger implementation that integrates with BepInEx's logging system.
Logs level can be adjusted setting ActiveLogLevels
Logs can be filtered by log level and tags, allowing for flexible logging configurations.
- ActiveTags for assigning active tags to the logger.
- InactiveTags for assigning tags that should be suppressed in logs.
private static readonly Logger logger = Logger.Create(typeof(MyPluginClass), LogTags.MyCustomTag);
logger.Debug("This is an debug message with {} argument.", "example");
logger.Info("This is an info message with {} argument.", "example");
logger.Warn("This is a warning message with {} argument.", "example");
logger.Error("This is an error message with an exception.", ex);
logger.Fatal("This is a fatal message with an exception.", ex);
public Logger(ManualLogSource logger, string pluginName, params ILogTag[] requiredTags)
Parameters
logger
ManualLogSourceThe BepInEx logging source to use.
pluginName
stringThe name of the plugin for which this logger is created.
requiredTags
ILogTag[]Optional tags that this logger requires to be active.
Properties
ActiveLogLevels
Our global logging defined listened log levels.
public static LogLevel ActiveLogLevels { get; }
Property Value
ActiveTags
Gets the active tags for this logger.
public static LogTag[] ActiveTags { get; }
Property Value
- LogTag[]
InactiveTags
Gets the inactive (suppressed) tags for this logger.
public static LogTag[] InactiveTags { get; }
Property Value
- LogTag[]
PluginName
Plugin name for which this logger is created.
public string PluginName { get; }
Property Value
Methods
Create(string, params ILogTag[])
Creates a new logger instance with the specified logging name and optional auto tags.
public static Logger Create(string loggingName, params ILogTag[] requiredTags)
Parameters
loggingName
stringThe name of the logging source.
requiredTags
ILogTag[]Optional required tags that this logger should include.
Returns
Create(Type, params ILogTag[])
Creates a new logger instance for the specified type, automatically determining the plugin name
public static Logger Create(Type loggingType, params ILogTag[] requiredTags)
Parameters
loggingType
TypeThe type for which the logger is being created. This type should be part of the plugin assembly.
requiredTags
ILogTag[]Optional tags that this logger should automatically include.
Returns
Create<T>(params ILogTag[])
Creates a new logger instance for the specified type, automatically determining the plugin name
public static Logger Create<T>(params ILogTag[] requiredTags)
Parameters
requiredTags
ILogTag[]Optional tags that this logger should automatically include.
Returns
Type Parameters
T
The type for which the logger is being created. This type should be part of the plugin assembly.
Enable(bool)
Sets whether this logger is enabled or disabled.
public void Enable(bool enable)
Parameters
enable
boolIf true, enables the logger; otherwise, disables it.
FindCallerStackFrame(StackTrace, int)
Finds the caller stack frame in the current stack trace, skipping a specified number of frames.
protected static StackFrame? FindCallerStackFrame(StackTrace stackTrace, int skipFrames)
Parameters
stackTrace
StackTraceThe stack trace to search for the caller frame.
skipFrames
intThe number of frames to skip before looking for the caller frame. Default is 2.
Returns
- StackFrame
The first stack frame that is not part of the Logger or ILogger, or the default frame if none is found.
GetBepLogLevel(int)
Get the BepInEx log level from an integer value.
protected static LogLevel GetBepLogLevel(int logLevelValue)
Parameters
logLevelValue
intThe integer value representing the log level.
Returns
- LogLevel
The corresponding BepInEx log level.
IsEnabled(int, ILogTag?)
Checks if the logger is enabled for the specified log level and category.
public bool IsEnabled(int logLevelValue, ILogTag? category = null)
Parameters
logLevelValue
intThe integer value representing the log level to check.
category
ILogTagThe optional log tag category to check against the active and inactive tags.
Returns
- bool
True if the logger is enabled for the specified log level and category; otherwise, false.
Log(LogLevel, string, int, params object[])
Logs a message with the specified log level, message, and optional arguments.
public void Log(LogLevel logLevel, string message, int methodTrace = 3, params object[] args)
Parameters
logLevel
LogLevelThe log level to use for the message.
message
stringThe message to log, which can include format placeholders.
methodTrace
intThe number of stack frames to skip when finding the caller method. Default is 3.
args
object[]Optional arguments to format the message with. If an argument is an exception, its message and stack trace will be included.
Log(int, string, int, params object[])
Logs a message with the specified log level value, message, and optional arguments.
public void Log(int logLevelValue, string message, int methodTrace = 2, params object[] args)
Parameters
logLevelValue
intThe integer value representing the log level.
message
stringThe message to log, which can include format placeholders.
methodTrace
intThe number of stack frames to skip when finding the caller method. Default is 2.
args
object[]Optional arguments to format the message with. If an argument is an exception, its message and stack trace will be included.