How to use Ilogger in my bot's custom action components?

135 Views Asked by At

Note: this is for bot framework composer projects.

I have setup serilog to be my implementation of ILogger and it works fine inside the root project (the actual chatbot) but not inside my custom action components.

I am aware that Ilogger works via Dependency Injection but I just can't figure out how to make it work inside custom action components. It always returns null in the constructor.

using Microsoft.Extensions.Logging;

public class SendSMSPaymentInformation : Dialog
{
   private readonly ILogger _logger;

   [JsonConstructor]
   public SendSMSPaymentInformation(ILogger<SendSMSPaymentInformation> logger, [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
       : base()
   {
       RegisterSourceLocation(sourceFilePath, sourceLineNumber);

       _logger = logger;
   }
  ...

I assume something has to be defined inside the "BotComponent" configuration method, but I am not sure what.

I should also clarify that I want to avoid using Serilog's static Log class as much as possible and not tie myself to a specific logging provider.

1

There are 1 best solutions below

3
Vinoth Rajendran On

Have you tried

dc.Context.TraceActivityAsync(...) ?

or you can pass the **ILogger BotController ** to custom action but It's not the best way because the logger always "BotController" class name even if you are using the Bot component class