Writing a log entry

Component: NServiceBus
NuGet Package NServiceBus (6.x)

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

public class ClassUsingLogging
    static ILog log = LogManager.GetLogger<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