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

标签 asp.net azure azure-devops azure-web-app-service sentry

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

这是我向 Sentry 记录异常的方法:

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 相关的内容。请建议我可以做什么来调试我的问题, 谢谢。

--编辑--

我能够收到错误消息。我收到此错误:“无法报告 session 错误,因为没有事件的.System.Object[]”

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

--编辑2--

捕获错误: 无法加载文件或程序集“System.Runtime.CompilerServices.Unsafe,Version=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 版本。因此,我更新了主机应用程序中的绑定(bind)重定向,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 有这个绑定(bind)重定向,但部署的 web.config 没有。

关于asp.net - 在 Azure 应用程序上部署时,Web 应用程序未将错误记录到 Sentry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69098034/

相关文章:

c# - 如何让所有用户从 Office Communicator 转到 asp.net 网页?

javascript - JQuery - 在 Asp.Net 客户端调用服务器端事件

c# - 如何取消选择列表框中的单个项目

azure - 使用 azure 逻辑应用创建具有多个工作表的 Excel

azure - 有没有办法查看 Azure CosmosDB 中当前的索引状态

javascript - 列表项背景颜色在 Ipad 上不会改变

azure - 无法从 powershell 恢复应用程序

azure - 使用 Azure DevOps 将文件复制到不同订阅中的 Azure Blob 存储

c# - 使用 visualstudio.com Team Services 构建失败,命名空间 'Optimization' 中不存在 'System.Web'

azure-devops - VSTS Microsoft 托管代理 : Virtual Machine size