Anotar Logging

Component: Anotar Logger
NuGet Package Anotar.NServiceBus.Fody (3.3)
This is a community run project
Target NServiceBus Version: 6.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:

<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:

public class MyHandler :
    IHandleMessages<MyMessage>
{
    public Task Handle(MyMessage message, IMessageHandlerContext context)
    {
        LogTo.Info("Hello from MyHandler");
        return Task.CompletedTask;
    }
}

This will result in the following being compiled

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

    public Task Handle(MyMessage message, IMessageHandlerContext context)
    {
        log.Info("Method: 'Task Handle(MyMessage, IMessageHandlerContext)'. Line: ~12. Hello from MyHandler");
        return Task.CompletedTask;
    }
}

Related Articles

  • Logging
    Manage and integrate with NServiceBus logging.

Last modified