我的WebForms应用程序面向.NET 4.7.2。我通过NuGet安装了Sentry 2.1.1。
当我的应用程序遇到未处理的异常时,应根据我的DSN捕获异常并将其记录到Sentry。
如下所示,命中了我的断点,捕获时出现了异常,但从未记录错误。
为什么我的错误没有记录到Sentry?
using System;
using Sentry;
public partial class FloorForceWeb : System.Web.HttpApplication
{
private IDisposable _sentry;
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
// Set up the sentry SDK
_sentry = SentrySdk.Init(o =>
{
o.Dsn = new Dsn("removed for security reasons...");
o.Environment = "Development";
});
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
void Application_End(object sender, EventArgs e)
{
_sentry.Dispose();
}
void Application_Error(object sender, EventArgs e)
{
var exception = Server.GetLastError();
SentrySdk.CaptureException(exception);
}
void Session_Start(object sender, EventArgs e)
{
}
void Session_End(object sender, EventArgs e)
{
}
}
注意:此代码改编自https://github.com/getsentry/sentry-dotnet-samples/blob/master/AspNetMvc5Ef6/Global.asax.cs
编辑:我在o.Debug = true;
处添加了o.DiagnosticsLevel = Sentry.Protocol.SentryLevel.Debug;
和SentrySdk.Init()
,但调试控制台中未记录任何内容:
答案 0 :(得分:1)
如果其他人遇到类似问题,我也遇到了一个问题,即 Sentry 没有给出任何问题的指示或信息。
我设法使用以下方法调试并找到了问题:
Global.asax.cs
return SentrySdk.Init(o =>
{
o.Debug = true;
o.DiagnosticLevel = SentryLevel.Debug;
o.DiagnosticLogger = new SentryConsoleDiagnosticLogger();
o.Dsn = "removed for security reasons...";
});
SentryConsoleDiagnosticLogger.cs
public class SentryConsoleDiagnosticLogger : IDiagnosticLogger
{
public SentryConsoleDiagnosticLogger()
{
}
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);
Debug.WriteLine(message, args);
}
}
就我而言,我需要为 Sentry 依赖项添加绑定重定向。