我正在使用 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/