Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bot Framework V4 IActivityLogger

Do We have any interface like IActivityLogger (V3) , in V4 to log all user activities?

I wanted to log all user queries and bots response in my cosmos db. I was able to do this in V3 using IActivityLogger interface.

Please suggest.

like image 575
Chithambara Kumar Avatar asked Apr 11 '19 12:04

Chithambara Kumar


2 Answers

The interface in V4 is 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

var transcriptStore = new MyCosmosTranscriptStore(config.TranscriptConnectionString, storageContainer);
var transcriptMiddleware = new TranscriptLoggerMiddleware(transcriptStore);
...
.AddSingleton(_ => transcriptStore);

Then add it to the adapter with adapter.Use(transcriptStore);

like image 73
Eric Dahlvang Avatar answered Oct 05 '22 14:10

Eric Dahlvang


Yes, we have ILoggerFactory interface in V4 which is used to log all user activities.

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.

like image 23
ranusharao Avatar answered Oct 05 '22 15:10

ranusharao