Anotar Logging

Component: Anotar Logger | Nuget: Anotar.NServiceBus.Fody (Version: 3.x - 3.1)
This is a community run project
Target NServiceBus Version: 5.x

This sample shows how to used the community run project Anotar to simplify logging when integrating with NServiceBus.

Anotar simplifies logging through a static class and some IL manipulation done by Fody. When using Anotar no static log field is necessary per class and extra information is captured for each log entry written.

Including Anotar

When the Anotar NuGet package is pulled in Fody will create a configuration file (FodyWeavers.xml) with the following:

Edit
<Weavers>
  <Anotar.NServiceBus />
</Weavers>

This tells the underlying Fody IL weaving engine to inject Anotar into the build pipeline.

Using Anotar LogTo

To use Anotar write a log entry via any of the static methods. For example in a handler:

Edit
public class MyHandler :
    IHandleMessages<MyMessage>
{
    public void Handle(MyMessage message)
    {
        LogTo.Info("Hello from MyHandler");
    }
}

This will result in the following being compiled

Edit
public class MyHandler :
    IHandleMessages<MyMessage>
{
    static ILog log = LogManager.GetLogger("MyHandler");

    public void Handle(MyMessage message)
    {
        log.Info("Method: 'Void Handle(MyMessage)'. Line: ~11. Hello from MyHandler");
    }
}

Related Articles

  • Logging
    Manage and integrate with NServiceBus logging.

Last modified