gpt4 book ai didi

azure - 机器人抛出异常时没有日志

转载 作者:行者123 更新时间:2023-12-03 02:48:13 24 4
gpt4 key购买 nike

我们有一个部署到 Azure 的 ASP.Net Core v4 机器人。使用 Azure 中的测试功能时效果很好。然后我们部署到 MS Teams。它可以正常查找,只不过每条消息后面都跟着另一条消息“抱歉,看起来出了点问题”。该消息通常在引发异常时发送。我尝试前往 Azure 查看日志,但它没有记录任何内容。

我们的代码中确实有 logger.LogError($"Exception catch : {exception.Message}"); ,我认为它会在生产时将其记录在某个地方。因此,我为机器人打开了 Application Insights,但它没有记录任何异常。我尝试从网络服务器流式传输日志,但抛出异常时它不会记录任何内容。

我尝试从“应用程序日志”和“Web 服务器日志”中查看应用程序日志

这是处理错误的代码:

public AdapterWithErrorHandler(IConfiguration configuration, ILogger<BotFrameworkHttpAdapter> logger, ConversationState conversationState = null)
: base(configuration, logger)
{
OnTurnError = async (turnContext, exception) =>
{
// Log any leaked exception from the application.
logger.LogError($"Exception caught : {exception.Message}");

// Send a catch-all apology to the user.
var errorMessage = MessageFactory.Text(ErrorMsgText, ErrorMsgText, InputHints.ExpectingInput);
await turnContext.SendActivityAsync(errorMessage);

if (conversationState != null)
{
try
{
// Delete the conversationState for the current conversation to prevent the
// bot from getting stuck in a error-loop caused by being in a bad state.
// ConversationState should be thought of as similar to "cookie-state" in a Web pages.
await conversationState.DeleteAsync(turnContext);
}
catch (Exception e)
{
logger.LogError($"Exception caught on attempting to Delete ConversationState : {e.Message}");
}
}
};
}

这是我们机器人的应用服务的日志设置:

enter image description here

最佳答案

@JohnGardner 是正确的。 Botframework catches all errors ,因此您 不会 可能不会在典型的 Azure 应用服务日志记录中看到它们。

@VinodkumarG 也是正确的,您可以看到 logger.LogError($"Exception caught : {exception.Message}"); 生成的错误在

Bot Management >> Build >>Open online code editor >> Output window

https://<yourEndpoint>.scm.azurewebsites.net/dev/wwwroot/:vs.output

<小时/>

您实际上应该能够在日志流 > 应用程序日志中看到这一点

我将其添加到我的机器人中:

enter image description here

测试中:

enter image description here

在输出中:

enter image description here

在日志流>应用程序日志中:

enter image description here

<小时/>

我们当前推荐的方法是使用 Application Insights。您可以使用Sample 21.Corebot-App-Insights作为指导。主要修改是如何在其 Startup.cs 中添加 App Insights :

完整

using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.ApplicationInsights;
using Microsoft.Bot.Builder.Integration.ApplicationInsights.Core;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.BotBuilderSamples.Bots;
using Microsoft.BotBuilderSamples.Dialogs;
using Microsoft.Extensions.DependencyInjection;

namespace Microsoft.BotBuilderSamples
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

// Create the credential provider to be used with the Bot Framework Adapter.
services.AddSingleton<ICredentialProvider, ConfigurationCredentialProvider>();

// Add Application Insights services into service collection
services.AddApplicationInsightsTelemetry();

// Create the telemetry client.
services.AddSingleton<IBotTelemetryClient, BotTelemetryClient>();

// Add ASP middleware to store the http body mapped with bot activity key in the httpcontext.items. This will be picked by the TelemetryBotIdInitializer
services.AddTransient<TelemetrySaveBodyASPMiddleware>();

// Add telemetry initializer that will set the correlation context for all telemetry items.
services.AddSingleton<ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();

// Add telemetry initializer that sets the user ID and session ID (in addition to other bot-specific properties such as activity ID)
services.AddSingleton<ITelemetryInitializer, TelemetryBotIdInitializer>();

// Create the telemetry middleware to track conversation events
services.AddSingleton<IMiddleware, TelemetryLoggerMiddleware>();

// Create the Bot Framework Adapter with error handling enabled.
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

// Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
services.AddSingleton<IStorage, MemoryStorage>();

// Create the User state. (Used in this bot's Dialog implementation.)
services.AddSingleton<UserState>();

// Create the Conversation state. (Used by the Dialog system itself.)
services.AddSingleton<ConversationState>();

// The Dialog that will be run by the bot.
services.AddSingleton<MainDialog>();

// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
services.AddTransient<IBot, DialogAndWelcomeBot<MainDialog>>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}

app.UseDefaultFiles();
app.UseStaticFiles();

//app.UseHttpsRedirection();
app.UseBotApplicationInsights();
app.UseMvc();
}
}
}

Diff vs CoreBot

您可能还会发现这篇博文很有用:Bot Analytics: Behind the Scenes

关于azure - 机器人抛出异常时没有日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57562487/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com