Writing a log entry

Component: NServiceBus | Nuget: NServiceBus (Version: 3.x)
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.

Set up a single static field to a ILog in the classes, and then use it in all methods, like this:

Edit
public class ClassUsingLogging
{
    static ILog log = LogManager.GetLogger(typeof(ClassUsingLogging));
    public void SomeMethod()
    {
        log.Debug("Something interesting happened.");
    }
}
When writing to a logger ensure the log level is of an equivalent value that will result in that log entry being written. So for example when calling .Debug(..) ensure that the log level is set to DEBUG. See Change settings via configuration.
Since LogManager.GetLogger(..); is an expensive call it is important that the field is static so that the call only happens once per class and have the best possible performance.

Last modified