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.
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With