Class LoggerMethodAttribute
Marks a method to be part of a logging module. If methods marked with this attribute are part of a call stack invoking ILogger methods, they will be treated as if they were part of the logging module.
[AttributeUsage(AttributeTargets.Method)]
public class LoggerMethodAttribute : Attribute
- Inheritance
-
LoggerMethodAttribute
- Inherited Members
Examples
For instance, stack traces in Unity console start at the first methods with this attribute. Double-clicking a log message in the console will also open the editor to the last call to a method with this attribute, not necessarily the call to the ILogger method.
public static class Example
{
private static readonly ILogger Logger = LoggerFactory.Create(typeof(Example));
[MenuItem("Example/Logger Method")]
public static void DoLogSomething()
{
MySuperLogMethod("Hello World!");
}
[LoggerMethod]
private static void MySuperErrorLogMethod(string message)
{
Logger.LogError(message);
}
}
In this example, MySuperLogMethod(string) will be considered part of the logging
system: double-clicking on the error log message will open the code editor
at the MySuperLogMethod("Hello World!"); line. And the log stack trace will start at
MySuperErrorLogMethod, and not mention Logger.LogError.