[英]Bot Framework V4 IActivityLogger
Do We have any interface like IActivityLogger (V3) , in V4 to log all user activities? 我们在V4中是否有像IActivityLogger(V3)这样的界面来记录所有用户活动?
I wanted to log all user queries and bots response in my cosmos db. 我想在我的cosmos db中记录所有用户查询和机器人响应。 I was able to do this in V3 using IActivityLogger interface.
我能够使用IActivityLogger接口在V3中完成此操作。
Please suggest. 请建议。
The interface in V4 is ITranscriptLogger 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);
}
}
Once you have an ITranscriptLogger implementation, it can be added to the middleware stack using TranscriptLoggerMiddleware 一旦有了ITranscriptLogger实现,就可以使用TranscriptLoggerMiddleware将其添加到中间件堆栈中
var transcriptStore = new MyCosmosTranscriptStore(config.TranscriptConnectionString, storageContainer);
var transcriptMiddleware = new TranscriptLoggerMiddleware(transcriptStore);
...
.AddSingleton(_ => transcriptStore);
Then add it to the adapter with adapter.Use(transcriptStore);
然后使用
adapter.Use(transcriptStore);
将其添加到适配器adapter.Use(transcriptStore);
Yes, we have ILoggerFactory interface in V4 which is used to log all user activities. 是的,我们在V4中有ILoggerFactory接口,用于记录所有用户活动。
For example: 例如:
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();
}
Attached here is the BotBuilder-Samples repo where you can find the conversation-history which uses the above interface. 附在此处的是BotBuilder-Samples回购,您可以在其中找到使用上述界面的对话历史记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.