Bot Framework V4 IActivityLogger

时间:2019-04-11 12:39:47

标签: c# .net .net-core botframework

在V4中,我们是否有诸如IActivityLogger(V3)之类的界面来记录所有用户活动?

我想将所有用户查询和漫游器响应记录在我的cosmos数据库中。我可以使用IActivityLogger界面在V3中做到这一点。

请提出建议。

2 个答案:

答案 0 :(得分:3)

V4中的界面为ITranscriptLogger

using System.Threading.Tasks;
using Microsoft.Bot.Schema;

namespace Microsoft.Bot.Builder
{
    /// <summary>
    /// Transcript logger stores activities for conversations for recall.
    /// </summary>
    public interface ITranscriptLogger
    {
        /// <summary>
        /// Log an activity to the transcript.
        /// </summary>
        /// <param name="activity">The activity to transcribe.</param>
        /// <returns>A task that represents the work queued to execute.</returns>
        Task LogActivityAsync(IActivity activity);
    }
}

一旦您有了 ITranscriptLogger 实现,就可以使用TranscriptLoggerMiddleware

将其添加到中间件堆栈中
var transcriptStore = new MyCosmosTranscriptStore(config.TranscriptConnectionString, storageContainer);
var transcriptMiddleware = new TranscriptLoggerMiddleware(transcriptStore);
...
.AddSingleton(_ => transcriptStore);

然后使用adapter.Use(transcriptStore);

将其添加到适配器中

答案 1 :(得分:0)

是的,我们在V4中具有ILoggerFactory接口,用于记录所有用户活动。

例如:

private ILoggerFactory _loggerFactory;

// Create a logger for the application to use.
ILogger logger = _loggerFactory.CreateLogger<ConversationHistoryBot>();

// Catches any errors that occur during a conversation turn and logs them.
options.OnTurnError = async (context, exception) =>
{
    logger.LogError($"Exception caught : {exception}");
    await context.SendActivityAsync("Sorry, it looks like something went wrong.");
};

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    _loggerFactory = loggerFactory;
    
    app.UseDefaultFiles()
       .UseStaticFiles()
       .UseBotFramework();
}

这里是BotBuilder-Samples存储库,您可以在其中找到使用上述界面的对话历史记录。