部署在 Azure 应用程序上时,Web 应用程序未将错误记录到 Sentry

Web Application not logging errors to Sentry when deployed on Azure App

我正在使用 Sentry 免费帐户记录我的应用程序中的错误。日志记录在我的开发环境中运行良好,但当我在 Azure 上部署应用程序时,错误不会推送到哨兵上。我检查了文件日志,Sentry 客户端 CaptureException 方法工作正常并返回了一个 SentryId,但是当我检查 Sentry.io 时,那里没有记录异常。 这是一个asp。净应用。 .Net 框架:4.6.1 哨兵客户端版本:3.9.0.0

这是我将异常记录到哨兵的方法:

public void LogException(Exception ex)
        {
            
                try
                {
                    if (ex == null) return;
                    var sentryId = SentrySdk.CaptureException(ex);
                    LogManager.Info(typeof(SentryManager),
                    $"SentrySdk.CaptureException(ex) called successfully. SentryId: {sentryId}");
                }
                catch (Exception e)
                {
                    LogManager.Error(typeof(SentryManager), $"SentryManager Exception - {e.Message + e.InnerException}", null);
                }
        }

我检查了我的 Azure 日志,没有发现与 Sentry 相关的内容。请建议我可以做些什么来调试我的问题, 谢谢

--编辑--

我能够收到错误消息。我收到此错误:“无法报告会话错误,因为存在 none active.System.Object[]”

谁能建议如何避免这种情况?

--编辑 2--

捕获到的错误: 无法加载文件或程序集‘System.Runtime.CompilerServices.Unsafe,版本=4.0.4.1,

首先,我必须找出导致问题的错误。为此,我编写了一个简单的记录器来记录从 Sentry SDK 生成的消息。 (来源:Sentry Not Logging Errors in WebForms App

public class SentryDiagnosticLogger : IDiagnosticLogger {
    public SentryDiagnosticLogger()
    {
    }

    public bool IsEnabled(SentryLevel level)
    {
        return true;
    }

    public void Log(SentryLevel logLevel, string message, Exception exception = null, params object[] args)
    {
        if (exception != null)
            throw new Exception("Sentry Exception occurred", exception);
    }
}

我的SDK初始化代码是这样的:

SentrySdk.Init(o =>
    {
        o.Dsn = config;
        o.Environment = ConfigurationManager.AppSettings["tavrtalk:Environment"];
        o.Debug = true;
        o.DiagnosticLevel = SentryLevel.Debug;
        o.DiagnosticLogger = new SentryDiagnosticLogger();
    });

终于报错了:

Could not load file or assembly System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1

我的项目中有 5.0.0 版本。因此,我在主机应用程序中更新了绑定重定向,Sentry SDK 自动选择了 System.Runtime.CompilerServices.Unsafe 程序集的更新版本。我在 web.config 文件中添加了以下配置:

<dependentAssembly>
    <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="*************" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>

这就是为什么 Sentry 在开发上运行良好的原因,因为 web.config 我的开发有这个绑定重定向,但部署的 web.config 没有。