Logging in RecoverabilityPolicy?

I have code like below. At most places ILogger is injected, but here I used LogManager, assuming it would also use ILogger and log to Application Insights.

I don’t see logs in Application Insights. Is mine assumtion wrong that LogManager is automaticlly configurated to use ILogger under the hood?

If I can’t use LogManager, is there a a built in way in NServiceBus to use ILogger? With Behaviors I can inject it, but is there a way to do it for a RecoverabilityPolicy?

public static class DataverseRecoverabilityPolicy
{
    static readonly ILog s_log = LogManager.GetLogger("DataverseRecoverabilityPolicy");

    public static RecoverabilityAction Invoke(RecoverabilityConfig config, ErrorContext context)
    {
        // recoverability logic
        
        // I want to log here
    }
}

Remy:

LogManager does not use ILogger by default. Have you configured NServiceBus to use the NServiceBus.Extensions.Logging package?

No, I’m not using NServiceBus.Extensions.Logging package because the NOTE says you shouldn’t use it when you use NServiceBus.Extensions.Hosting.

So, because of this NOTE, I assumed that LogManager is already automatically wired up to use the ILogger infrastructure.

I only use LogManager here, in my RecoverabilityPolicy because it allows me to create it directly without Dependency Injection.

Sorry about that.

It is wired up, but only after the generic host initializes it.

This is likely because the logging isn’t configured until after the static ILogger is populated as part of the NServiceBus configuration.

We are working on trying to create a sample that would work in your situation. We will update this thread when we have one for you (or if we are unable to create one).

  • Your case team (Bob, Tamara, and Travis)