简体   繁体   English

如何在我的机器人的自定义操作组件中使用 Ilogger?

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

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.我将 serilog 设置为我的 ILogger 实现,它在根项目(实际的聊天机器人)中运行良好,但在我的自定义操作组件中运行不正常。

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.我知道 Ilogger 通过依赖注入工作,但我只是不知道如何让它在自定义操作组件中工作。 It always returns null in the constructor.它总是在构造函数中返回 null。

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.我假设必须在“BotComponent”配置方法中定义一些东西,但我不确定是什么。

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.我还应该澄清一下,我想尽可能避免使用 Serilog 的 static Log class 并且不将自己绑定到特定的日志记录提供商。

you can add Dependency Injection in Startup.cs file你可以在 Startup.cs 文件中添加依赖注入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM